网站首页  词典首页

请输入您要查询的函数:

 

术语 waitforsingleobject
释义 WaitForSingleObject
语法:
C++
DWORD WINAPI WaitForSingleObject(
__in HANDLE hHandle,
__in DWORD dwMilliseconds
);
WaitForSingleObject函数
等待,直到指定的对象是在信号状态或超时时间间隔经过的。
要输入一个报警等待状态,请使用WaitForSingleObjectEx功能。等待多个对象,使用WaitForMultipleObjects的。
参数
hHandle [in]
句柄的对象。对于一个对象的句柄类型可以指定清单,请参阅下面的备注部分。
如果这个处理是封闭,而该等待仍悬而未决,该函数的行为是不确定的。
句柄必须有正确的同步访问。有关更多信息,请参阅标准访问权限。
dwMilliseconds的 [in]
在超时间隔时间,以毫秒为单位。如果一个非零值指定的函数等待直到该对象发出信号,或经过的时间间隔。如果dwMilliseconds的是零,该函数不进入等待状态,如果该对象不是信号,它总是立即返回。如果dwMilliseconds的是无限的,该函数将返回只有当对象发出信号。
返回值
如果函数成功,返回值表示该事件导致该函数返回。它可以是下列值之一。
返回代码/ valueDescription
WAIT_ABANDONED
0x00000080LThe指定的对象是一个互斥对象,即不拥有前拥有线程终止了互斥对象的线程释放。对互斥对象的所有权被授予调用线程的互斥体状态设置为无信号。
假如是互斥保护的持久状态的信息,您应该检查它的一致性。
WAIT_OBJECT_0
指定对象的0x00000000LThe状态信号。
WAIT_TIMEOUT
0x00000102LThe超时时间间隔过去了,该对象的状态是无信号。
WAIT_FAILED
(DWORD值)0xFFFFFFFFThe函数失败。为了获得更多错误信息,调用GetLastError。
备注
WaitForSingleObject函数检查指定对象的当前状态。如果该对象的状态是无信号,调用线程进入等待状态,直到超时间隔经过的对象发出信号或时间。
函数修改了某些类型的同步对象的状态。改造不仅对对象的信号状态发生所造成的函数返回。例如,一个信号量对象计数减少1。
WaitForSingleObject函数可以等待下列对象:
更改通知
控制台输入
事件
内存资源通知
互斥
工艺
信号量
线
可等待定时器
使用时要小心调用等待函数和代码直接或间接产生的窗口。如果一个线程创建的窗口,它必须处理消息。广播消息发送到系统中的所有窗口。一个线程使用,没有时间等待功能超时间隔可能会导致系统变得陷入僵局。两个代码,间接创造DDE和窗口的CoInitialize函数的例子。因此,如果您有一个线程创建的窗口,而不是使用WaitForSingleObject MsgWaitForMultipleObjects或MsgWaitForMultipleObjectsEx。
实例
有关示例,请参阅使用互斥对象。
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
参见
同步功能
等待函数
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==WaitForSingleObject Function
Waits until the specified object is in the signaled state or the time-out interval elapses.
To enter an alertable wait state, use the WaitForSingleObjectEx function. To wait for multiple objects, use the WaitForMultipleObjects .
Syntax
C++
DWORD WINAPI WaitForSingleObject(
__in HANDLE hHandle,
__in DWORD dwMilliseconds
);
Parameters
hHandle [in]
A handle to the object. For a list of the object types whose handles can be specified, see the following Remarks section.
If this handle is closed while the wait is still pending, the function's behavior is undefined.
The handle must have the SYNCHRONIZE access right. For more information, see Standard Access Rights .
dwMilliseconds [in]
The time-out interval, in milliseconds. If a nonzero value is specified, the function waits until the object is signaled or the interval elapses. If dwMilliseconds is zero, the function does not enter a wait state if the object is not signaled; it always returns immediately. If dwMilliseconds is INFINITE, the function will return only when the object is signaled.
Return Value
If the function succeeds, the return value indicates the event that caused the function to return. It can be one of the following values.
Return code/valueDescription
WAIT_ABANDONED
0x00000080LThe 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_0
0x00000000LThe state of the specified object is signaled.
WAIT_TIMEOUT
0x00000102LThe time-out interval elapsed, and the object's state is nonsignaled.
WAIT_FAILED
(DWORD)0xFFFFFFFFThe function has failed. To get extended error information, call GetLastError .

Remarks
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 until the object is signaled or the time-out interval elapses.
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.
The WaitForSingleObject function can wait for the following objects:
Change notification
Console input
Event
Memory resource notification
Mutex
Process
Semaphore
Thread
Waitable timer
Use caution when calling the wait functions and code that directly or indirectly creates windows. If a thread creates any windows, it must process messages. Message broadcasts are sent to all windows in the system. A thread that uses a wait function with no time-out interval may cause the system to become deadlocked. Two examples of code that indirectly creates windows are DDE and the CoInitialize function. Therefore, if you have a thread that creates windows, use MsgWaitForMultipleObjects or MsgWaitForMultipleObjectsEx , rather than WaitForSingleObject.
Examples
For an example, see Using Mutex Objects .
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
See Also
Synchronization Functions
Wait Functions
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms687032(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:16:19