Returns when any or all the specified objects is signaled or timeout occurs.
[ enWait = ] WaitForMultipleObjects ( ahObject, bWaitAll [,lTimeout] )
The WaitForMultipleObjects property syntax has the following parts:
Name |
Type |
Description |
enWait |
Val enumAWaitForReturn |
A number specifying the event that caused the function to return. |
ahObject |
Val Variant |
Array of object handles. |
bWaitAll |
Val Bool |
A Boolean expression specifying the wait type. |
lTimeout |
[Val] Long |
The time-out interval in milliseconds. This is optional. The default is -1 (infinite); that is, the function's time-out interval never elapses. See below also. |
bWaitAll can have one of the following values:
Value |
Description |
True * |
The function returns when the states all objects in the array of handles are signaled. |
False |
The function returns when the state of any one of the objects is signaled. The return value indicates the object whose state caused the function to return. |
Name |
Value |
Description |
awaitFailed |
-1 |
Failed. |
awaitObject0 to (awaitObject0 + number of handles – 1) |
0 to number of handles-1 |
Object is signaled. If bWaitAll is TRUE, the return value indicates that the state of all specified objects is signaled. If bWaitAll is FALSE, the return value minus waitObject0 indicates the index of the object in the ahObject array that satisfied the wait. If more than one object became signalled during the call, this is the array index of the signalled object with the smallest index value of all the signalled objects. |
awaitAbandoned0 to (awaitAbandoned0 + number of handles – 1) |
0x80 (128) to 0x80 plus number of handles -1 |
Object thread terminated. If bWaitAll is TRUE, the return value indicates that the states of all specified objects are signaled and at least one of the objects is an abandoned mutex object. If bWaitAll is FALSE, the return value minus waitAbandoned0 indicates the index of an abandoned mutex object in the ahObject array that satisfied the wait. |
awaitTimeout |
0x102 (258) |
Timeout. The time-out interval elapsed and the conditions specified by the bWaitAll parameter are not satisfied. |
The WaitForMultipleObjects function returns when one of the following occurs:
Either any one or all of the specified objects are in the signaled state.
The time-out interval elapses.
The WaitForMultipleObjects function determines whether the wait criteria have been met. If the criteria have not been met, the calling thread enters an efficient wait state, consuming very little processor time while waiting for the criteria to be met.
When bWaitAll is TRUE, the function's wait operation is completed only when the states of all objects have been set to signaled. The function does not modify the states of the specified objects until the states of all objects have been set to signaled. For example, a mutex can be signaled, but the thread does not get ownership until the states of the other objects are also set to signaled. In the meantime, some other thread may get ownership of the mutex, thereby setting its state to nonsignaled.
Before returning, a wait function modifies the state of some types of synchronization objects. Modification occurs only for the object or objects whose signaled state caused the function to return. For example, the count of a semaphore object is decreased by one. When bWaitAll is FALSE, and multiple objects are in the signaled state, the function chooses one of the objects to satisfy the wait; the states of the objects not selected are unaffected.
The WaitForMultipleObjects function can specify handles of any of the following object types in the handles array:
Event
Mutex
Semaphore
Thread
Other Windows handles may be used such as: Change notification, Console input, Job, Process, Timer-queue timer or 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.
The lTimeOut default value is -1, infinite time-out. The function returns if the interval elapses, even if the conditions specified by the bWaitAll parameter are not met. If lTimeout is zero, the function tests the states of the specified objects and returns immediately. If lTimeout is -1 (infinite), the function's time-out interval never elapses.
The following statement returns when all the objects in the ah array are signaled (either the thread is complete or the mutex is signaled) or 650 millisecond elapses first:
ah[0]=ev.Handle
ah[1]=hThread
select WaitForMultipleObjects(ah, False, 650)
case awaitTimeout
print "Error"
case awaitFailed
print "Timeout"
case 0 to 1
print "Either object is complete"
endselect
AEvent, AMutex, ASemaphore, CreateThread, WaitForSingleObject, WaitForEvent