views:

335

answers:

4

If I create an event using CreateEvent in Windows, how can I check if that event is signaled or not using the debugger in Visual Studio? CreateEvent returns back a Handle, which doesn't give me access to much information. Before I call WaitForSingleObject(...), I want to check to see if the event is signaled before I step into the function.

A: 

If the event is signaled and you use WaitForSingleObject(), it will return immediately. Also, you can call WaitForSingleObject() with a wait time of 0 to determine if it is signaled or not. However, that should not be necessary -- set the initial state in the CreateEvent() call (what has elapsed so far is unclear in your question).

Kris Kumler
A: 

Thanks Kris. I didn't want to add any extra code. I'm trying to synchronize 2 threads by using events. I have a WaitForSingleObject( eventHandle, INFINITE ) in the 2nd thread and have a placed a breakpoint there. Before I invoke that instruction, I was wondering if I could mnaually check (through some window or command prompt) if the the eventHandle is signaled or not.

lazy coder
Has your question now been answered to satisfaction?
Kris Kumler
+2  A: 

You can use the Process Explorer tool (http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) to manually check the event outside of the debugger. It helps if the event is named, so that you can find it easier.

Kris Kumler
+1  A: 

Use the handle command. Here is a sample

The following command displays detailed information about handle 0x8.

0:000> !handle 8 f

Handle 8 Type Event Attributes 0 GrantedAccess 0x100003: Synch QueryState,ModifyState HandleCount 2 PointerCount 3 Name Object Specific Information Event Type Auto Reset Event is Waiting

Note that this command is for Debugging Tools for Windows (WinDbg / ntsd / cdb / kd), not Visual Studio. DTW is at http://www.microsoft.com/whdc/devtools/debugging/default.mspx
bk1e