How to release a thread from a Monitor blocking?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I’m writing a thread wrapper for a safe thread termination by using stop event.
Whenever the thread stop event is signaled, I want to release the thread in
case it’s blocked on Monitor.Enter() or Monitor.Wait().
Note that when I’m writing this code, I do not know on what object the
Monitor will block on.
Is there a way to release the thread from the Monitor blocking except using
Thread.Interrupt() (Any kind of wrapping is acceptable) ???
 
Sharon,

Interrupt is the only thing that will stop the blocking. The only other
thing I could think of that would stop it would be to actually find the
object that is currently holding the lock, and release it on the thread that
is holding it. However, that doesn't guarantee that your thread will wake
up, because there might be other threads trying to lock on that same object.

Hope this helps.
 
Why do you not want to use Interrupt in this situation - thats exactly what its there for

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

I'm writing a thread wrapper for a safe thread termination by using stop event.
Whenever the thread stop event is signaled, I want to release the thread in
case it's blocked on Monitor.Enter() or Monitor.Wait().
Note that when I'm writing this code, I do not know on what object the
Monitor will block on.
Is there a way to release the thread from the Monitor blocking except using
Thread.Interrupt() (Any kind of wrapping is acceptable) ???
 
Back
Top