看你在用CreateEvent()创建事件时选择是自动复位还是手工复位。bManualReset [in] Boolean that specifies whether a manual-reset or auto-reset event object is created. If TRUE, then you must use the ResetEvent function to manually reset the state to nonsignaled. If FALSE, the system automatically resets the state to nonsignaled after a single waiting thread has been released.
Res The WaitForSingleObject function checks the current state of the specified object. If the object's state is nonsignaled, the calling thread enters the wait state. It uses no processor time while waiting for the object state to become signaled or the time-out interval to elapse.The function modifies the state of some types of synchronization objects. Modification occurs only for the object whose signaled state caused the function to return. For example, the count of a semaphore object is decreased by one.但我的MSDN2004是这样说的
MSDN这样说: The WaitForSingleObject function returns when one of the following occurs: The specified object is in the signaled state. The time-out interval elapses. DWORD WaitForSingleObject( HANDLE hHandle, // handle to object to wait for DWORD dwMilliseconds // time-out interval in milliseconds ); hHandle-->指向同步对象的指针。事件对象其实是同步对象的一种。 dwMilliseconds --> 等待同步对象变成”有信号”前等待的时间,以毫秒计。当等待的时间超过该值后无信号同步对象仍处于”无信号”状态,线程不再等待,WaitForSingleObject函数会返回。如果想要线程一直等待,应该把该参数设为INFINITE(该值等于0xffffffff)。所以如果你没有设置INFINITE则返回时状态不定 设置了WaitForSingleObject(hEvent,INFINITE)后要复位信号则需要用 BOOL ResetEvent( HANDLE hEvent // handle to event object );
[in] Boolean that specifies whether a manual-reset or auto-reset event object is created. If TRUE, then you must use the ResetEvent function to manually reset the state to nonsignaled. If FALSE, the system automatically resets the state to nonsignaled after a single waiting thread has been released.
手动的话,就需要SetEvent()置位
The WaitForSingleObject function checks the current state of the specified object. If the object's state is nonsignaled, the calling thread enters the wait state. It uses no processor time while waiting for the object state to become signaled or the time-out interval to elapse.The function modifies the state of some types of synchronization objects. Modification occurs only for the object whose signaled state caused the function to return. For example, the count of a semaphore object is decreased by one.但我的MSDN2004是这样说的
The WaitForSingleObject function returns when one of the following occurs: The specified object is in the signaled state.
The time-out interval elapses. DWORD WaitForSingleObject(
HANDLE hHandle, // handle to object to wait for
DWORD dwMilliseconds // time-out interval in milliseconds
);
hHandle-->指向同步对象的指针。事件对象其实是同步对象的一种。
dwMilliseconds --> 等待同步对象变成”有信号”前等待的时间,以毫秒计。当等待的时间超过该值后无信号同步对象仍处于”无信号”状态,线程不再等待,WaitForSingleObject函数会返回。如果想要线程一直等待,应该把该参数设为INFINITE(该值等于0xffffffff)。所以如果你没有设置INFINITE则返回时状态不定
设置了WaitForSingleObject(hEvent,INFINITE)后要复位信号则需要用
BOOL ResetEvent(
HANDLE hEvent // handle to event object
);