Jump to content
  • Advertisement
Sign in to follow this  
Zipster

[.net] [C#] :: ThreadAbortException not thrown when blocking on ReadToEnd

This topic is 3897 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone. I'm running into a strange issue where if I spawn a new thread, then spawn a process (unmanaged application) in that thread via the Process class and redirect its output to a stream, the thread won't receive a ThreadAbortException if it's blocked on a ReadToEnd call at the time of the abort. It doesn't throw anything at all, it just seems to terminate silently. This is problematic because if the thread is aborted by the user, I need to terminate the process it spawned. Unfortunately, I couldn't get asynchronous stream reading to work at all. I followed the documentation to a 'T' and my output callback was never called (yes, it was added to the event), resulting in the spawned process blocking forever once its output stream filled up. It didn't make much sense to spawn yet another thread to read the stream asynchronously anyway if I already had a separate thread for spawning the process, which is why I stuck with ReadToEnd. But now I can't receive any exceptions! Is it expected behavior to not receive this exception on waiting threads when they're terminated? And if so, how do I get around it? [Edited by - Zipster on March 14, 2008 6:44:18 PM]

Share this post


Link to post
Share on other sites
Advertisement
Nevermind guys, I found a workaround. I decided to manually call ReadToEnd with BeginInvoke to make it asynchronous :)

EDIT: Ok, that didn't work either. The bottom line is that if the child process fills up the output stream, my application never empties it, and both sit around forever. If the stream is closed by the child process before being filled, then everything is fine. However the documentation makes it pretty clear that ReadToEnd should still work in this circumstance. All this should be so simple, it's frustrating that I have to jump through hoops to get it to work. Spawn a process, capture its stdout.

[Edited by - Zipster on March 15, 2008 7:29:10 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!