win32 event event

Original Address: https: //blog.csdn.net/u011394598/article/details/82981399

SetEvent / ResetEvent EVENT, respectively, these two states are set to be not signal the signal.

The WaitForSingleObject () waits until only returns specified by the parameters OBJECT signal state becomes, the EVENT OBJECT may be, may be other kernel objects. Note: The first parameter WaitForSingleObject must not be empty.

CreateEvent used to create or open or unnamed event object named for its other explanation, your own words, here only a brief description of its two common usage!

CreateEvent defined as follows:

HANDLE WINAPI CreateEvent (  
_In_opt_ LPSECURITY_ATTRIBUTES lpEventAttributes, // security attributes
_In_ BOOL bManualReset, // reset mode set signal for the automatic recovery of non-signal state (FALSE) or manually restore the non-signal state (TRUE)
 _In_ BOOL bInitialState // initial state  
 _In_opt_ LPCTSTR lpName // signal names may be Null
);



use:
a first automatic return to the non-signal state

hEvent = CreateEvent (NULL, FALSE, TRUE, NULL); // reset mode is automatically restored to the non-signal state, and the initial state is signaled.
DWORD dReturn the WaitForSingleObject = (the hEvent, wait time); // End i.e. the method invoked after, hEvent becomes no signal state, need to call setEvent it signaled state


hEvent will become non-signal state, if you need the above formula and set up again at some point through, you need to use the following statement it becomes signaled (in this way can only unlock a waiting thread, need to continue to unlock, you need to use the following equation again)

SetEvent (hEvent)


the second case to manually restore the non-signal state

hEvent = CreateEvent (NULL, TRUE, TRUE, NULL); // manual reset mode is restored to the non-signal state, and the initial state is signaled.
DWORD dReturn the WaitForSingleObject = (the hEvent, wait time); // call this method, there is automatically changed event signal


hEvent will automatically become signaled again, the above formula will be executed directly and also through direct execution and pass (there are multiple threads waiting Over), if necessary hEvent set to the non-signal state, it is necessary to manually use the following statement:

the ResetEvent (hEvent);


NOTE: The above reset mode refers to a return to the way non-signal state, if set to TRUE, it indicates need to manually set to no signal, if is FALSE, it automatically becomes a no signal, and the signal amount becomes do not signaled way confused!

Guess you like

Origin www.cnblogs.com/dragon2012/p/11694413.html