WaitForSingleObject是一種Windows API函式,當等待仍在掛起狀態時,句柄被關閉,那么函式行為是未定義的。該句柄必須具有 SYNCHRONIZE 訪問許可權。
WaitForSingleObject函式用來檢測hHandle事件的信號狀態,在某一執行緒中調用該函式時,執行緒暫時掛起,如果在掛起的dwMilliseconds毫秒內,執行緒所等待的對象變為有信號狀態,則該函式立即返回;如果逾時時間已經到達dwMilliseconds毫秒,但hHandle所指向的對象還沒有變成有信號狀態,函式照樣返回。
基本介紹
- 中文名:WaitForSingleObject
- 外文名:WaitForSingleObject
- 聲明位置:synchapi.h
- 返回值類型:unsigned long
- 調用方式:__stdcall
- 參數類型:(void*,unsigned long)
對應函式
說明
參數
返回值
WAIT_ABANDONED0x00000080L | The specified object is a mutex object that was not released by the thread that owned the mutex object before the owning thread terminated. Ownership of the mutex object is granted to the calling thread and the mutex state is set to nonsignaled. If the mutex was protecting persistent state information, you should check it for consistency. |
WAIT_OBJECT_00x00000000L | The state of the specified object is signaled. |
WAIT_TIMEOUT0x00000102L | The time-out interval elapsed, and the object's state is nonsignaled. |
WAIT_FAILED(DWORD)0xFFFFFFFF | The function has failed. To get extended error information, callGetLastError. |
UINT CFlushDlg::MyThreadProc( LPVOID pParam ){WaitForSingleObject(g_event,INFINITE);For(;;){………….}return 0;}
UINT CFlushDlg::MyThreadProc( LPVOID pParam ){while(WaitForSingleObject(g_event,MT_INTERVAL)!=WAIT_OBJECT_0){………………}return 0;}