比如说你打开了记事本,然后使用WaitForSingleObject去等待这个进程(或者是你在程序中打开一个线程),并且可以指定等待的时间或者指定只有当这个进程(或线程)关闭后,此处的程序才往下走,否则的话,在等待过程中,程序处于无响应状态。
你在你的程序中,在 WaitForSingleObject 下面设置一个端点,然后通过改变 WaitForSingleObject 函数的参数,你就马上能够明白这个函数是干什么用的了。
看看MSDN的说明
WaitForSingleObject
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
);
Parameters
hHandle
Handle to the object. For a list of the object types whose handles can be specified, see the following Remarks section.
Windows NT: The handle must have SYNCHRONIZE access. For more information, see Standard Access Rights.
dwMilliseconds
Specifies the time-out interval, in milliseconds. The function returns if the interval elapses, even if the object's state is nonsignaled. If dwMilliseconds is zero, the function tests the object's state and returns immediately. If dwMilliseconds is INFINITE, the function's time-out interval never elapses.
Return Values
If the function succeeds, the return value indicates the event that caused the function to return. This value can be one of the following.
Value Meaning
WAIT_ABANDONED 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 is set to nonsignaled.
WAIT_OBJECT_0 The state of the specified object is signaled.
WAIT_TIMEOUT The time-out interval elapsed, and the object's state is nonsignaled.
If the function fails, the return value is WAIT_FAILED. To get extended error information, call GetLastError.
--------------------next---------------------
阅读(293) | 评论(0) | 转发(0) |