请问 WaitForSingleObject函数返回后是否将事件对象重置为无信号状态,还是保持为有信号状态

解决方案 »

  1.   

    看你在用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. 
      

  2.   

    对于以自动复位方式创建的事件对象,在其置位后一被WaitForSingleObject()等待到就会立即复位
    手动的话,就需要SetEvent()置位
      

  3.   

    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是这样说的
      

  4.   

    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
    );
      

  5.   

    需要看你等待的HANDLE的类型,MuteX、Event、Semaphore、或线程HANDLE,不一样的。