views:

25

answers:

1

If I use CreateEvent to open an event:

 responseWaitEvent = CreateEvent(NULL,        // no security
  TRUE,       // manual-reset event
  FALSE,      // not signaled
  (LPTSTR)eventName); // event name

And this event already exists and has been signaled. Will this call reset the signal (because of setting initial state to FALSE).

Or will it immediately exit the wait when called:

 if (responseWaitEvent)
 {
  DWORD dw = WaitForSingleObjectEx(responseWaitEvent, m_ResponseTimeoutMillis, FALSE);
+1  A: 

The second call will open the event, it will not change the event's state.

I know this because the documentation says that it opens it but not that it resets it. If it reset it, that would be important enough to mention.

HANDLE responseWaitEvent = CreateEvent(NULL,        // no security
    TRUE,       // manual-reset event
    TRUE,      // signaled
    (LPTSTR)_T("TESTEvent")); // event name
    assert(responseWaitEvent && "Could not create event");

responseWaitEvent = CreateEvent(NULL,        // no security
    TRUE,       // manual-reset event
    FALSE,      // not signaled
    (LPTSTR)_T("TESTEvent")); // event name

    assert(responseWaitEvent && "Could not open event");

DWORD dw = WaitForSingleObjectEx(responseWaitEvent, 10000, FALSE);
assert(dw != WAIT_TIMEOUT);

And the opposite:

HANDLE responseWaitEvent2 = CreateEvent(NULL,        // no security
    TRUE,       // manual-reset event
    FALSE,      // not signaled
    (LPTSTR)_T("TESTEvent2")); // event name
    assert(responseWaitEvent && "Could not create event");

responseWaitEvent2 = CreateEvent(NULL,        // no security
    TRUE,       // manual-reset event
    TRUE,      // signaled
    (LPTSTR)_T("TESTEvent2")); // event name
    assert(responseWaitEvent && "Could not open event");

DWORD dw2 = WaitForSingleObjectEx(responseWaitEvent2, 10000, FALSE);
assert(dw2 == WAIT_TIMEOUT);
Brian R. Bondy
And the wait will immediately exit because the event has already been signaled, correct?
Mike
@Mike: Yup in example 1 above it will return instantly, in example 2 it will wait 10 seconds then return.
Brian R. Bondy