How to find what state ManualResetEvent is in?

George Mauer picture George Mauer · Dec 23, 2008 · Viewed 18.9k times · Source

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

That is to say I would like to know if the ManualResetEvent is currently blocking any threads and maybe even how many and which threads it is blocking.

Answer

Andrew Rollings picture Andrew Rollings · Dec 23, 2008

Perform a WaitOne on the event with a timeout value of zero.

It will return true if the event is set, or false if the timeout occurs. In other words, true -> event is set, false -> event is not set.