views:

319

answers:

1

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.

+6  A: 

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

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

Andrew Rollings
Thats a good idea, the debugger allows me to check its internals though, can't I find the state somewhere in there?
George Mauer
Hmm... Dunno. I seem to recall that it's an opaque object and not much help to look at.However, you can probably execute the WaitOne call in the Immediate Window during debugging :)
Andrew Rollings