1

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.

IndustProg
  • 627
  • 1
  • 13
  • 33
lazy coder
  • 11
  • 4

3 Answers3

7

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
  • 6,307
  • 3
  • 24
  • 27
4

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

computinglife
  • 4,321
  • 1
  • 21
  • 18
  • 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 Sep 25 '08 at 05:41
  • @bk1e: That's true. However, it's also [possible to use the Windows Debugger Engine from Visual Studio](http://stackoverflow.com/q/3438489/1889329), so the `!handle` extension command is available in Visual Studio as well. – IInspectable Jan 23 '15 at 17:08
1

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
  • 6,307
  • 3
  • 24
  • 27