Windows API Reference

SetEvent

The SetEvent function sets the specified event object to the signaled state.

Event objects are synchronization primitives that can be used to signal the occurrence of an event. Multiple threads can wait for an event to become signaled.

Syntax

BOOL SetEvent(
   HANDLE hEvent
);

Parameters

  • hEvent: A handle to the event object.

The handle must have the EVENT_MODIFY_STATE access right.

Return Value

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

When a thread calls SetEvent, the state of the event object is set to signaled. Any threads that were waiting for the event to become signaled are released.

If an event is auto-reset (created by calling CreateEvent with bManualReset = FALSE), SetEvent resets the event object to the nonsignaled state after releasing one waiting thread. If an event is manual-reset (created by calling CreateEvent with bManualReset = TRUE), SetEvent leaves the event object in the signaled state until ResetEvent is called.

To create an event object, use the CreateEvent function.

SetEvent increments the event object's reference count. This does not affect the object's behavior or its signaled state.

Example:

// Assume hMyEvent is a valid handle to an event object
// created with CreateEvent(...);

if (SetEvent(hMyEvent)) {
    // Event was successfully signaled
} else {
    // Handle error
    DWORD error = GetLastError();
}

Requirements

Minimum supported client: Windows XP

Minimum supported server: Windows Server 2003

Header: windows.h

Library: Use Kernel32.lib

DLL: Kernel32.dll

See Also