How to find out what condition ManualResetEvent is in?

I am using an instance of ManualResetEvent to control streaming access to a resource, but I am having problems with it. Does anyone know how I can find out during debugging what the state of an object is?

That is, I would like to know whether ManualResetEvent blocks any threads and, possibly, even how many and which threads are blocked.

+55
multithreading locking
Dec 23 '08 at 15:43
source share
2 answers

Execute a WaitOne in an event with a timeout value of zero.

It will return true if the event is set, or false if a timeout occurs. In other words, set to true →, false → the event is not set.

+71
Dec 23 '08 at 15:52
source share

Here is the working code:

 private ManualResetEvent pause = new ManualResetEvent(false); pause.WaitOne(); // caller thread pauses pause.Set(); // another thread releases paused thread // Check pause state public bool IsPaused { get { return !pause.WaitOne(0); } } 
+7
Aug 7 '11 at 19:35
source share



All Articles