I have a thread that waits on TcpListener.AcceptTcpClient()
, which blocks, which I want to suspend at times.
I've read about Monitor.Wait(...)
, but I only have experience working with mutexes and if the thread waits on a blocking method, it gets interesting.
Now that Thread.Suspend(...)
is obsolete, how should I suspend the thread?
This is not possible, it is an unsolvable race condition. The listener could have accepted a connection a microsecond before you want to suspend it. Closing the listener so it won't accept any connections is the only sure way.
Rethink your logic here. Whatever it is going to do with that connection that makes you want to stop it probably needs to be locked instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With