Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aborting blocking thread

I have a thread that is blocking on a Networkstream Read call. How do I best abort this thread? I tried calling Thread.Abort on the thread from another thread, which according to MSDN should raise a ThreadAbortException. However the ThreadAbortException is not raised at all in the thread. It is however, when I remove the blocking Read call and just have the thread sit in a loop. What is the best way to do this? Can I wait on the Read call and an event at the same time so the thread unblocks if either occurs? Then I could just signal that event from another thread.

like image 370
PaulK Avatar asked Jun 01 '26 19:06

PaulK


1 Answers

Close the socket! The Read should then throw an exception.

like image 84
Martin James Avatar answered Jun 03 '26 14:06

Martin James