WaitForMultipleObjects

  DWORD WaitForMultipleObjects(nCount, lpHandles, bWaitAll, dwMilliseconds)    
  DWORD nCount;    
  LPHANDLE lpHandles;    
  BOOL bWaitAll;    
  DWORD dwMilliseconds;    

A wait operation on multiple waitable objects (up to MAXIMUM_WAIT_OBJECTS) is accomplished with the WaitForMultipleObjects function:

Parameters

nCount

A count of the number of objects that are to be waited on.

lpHandles

An array of object handles. Each handle must have SYNCHRONIZE access to the associated object. It is an error for the same object to be specified more than once (even if different handle values are used to refer to the object).

bWaitAll

A flag that supplies the wait type. A value of TRUE indicates a “wait all”. A value of FALSE indicates a “wait any”. In a successful wait all, the wait is not satisfied unless all of the objects attain the signaled state at the same time.

dwMilliseconds

A time-out value that specifies the relative time, in milliseconds, over which the wait is to be completed. A timeout value of 0 specifies that the wait is to timeout immediately. This allows an application to test an object to determine if it is in the signaled state. A timeout value of INFINITE specifies an infinite timeout period.

Return Value

The following list shows the possible return values:

Value Meaning

WAIT_TIMEOUT  
  The wait was terminated because the timeout time was reached.
0 to MAXIMUM_WAIT_OBJECTS – 1  
  In the case of wait for any object, the object number which satisfied the wait. In the case of wait for all objects, the value indicates only that the wait was completed successfully.
WAIT_ABANDONED_0 to WAIT_ABANDONED_0 + (MAXIMUM_WAIT_OBJECTS – 1)  
  In the case of wait for any object, the object number which satisfied the event, and that the object which satisfied the event was a mutex object and was abandoned. In the case of wait for all objects, the value indicates that the wait was completed successfully and at least one of the objects was a mutex object and was abandoned.
0xFFFFFFFF  
  An error occurred. Use the GetLastError function to obtain extended error information.

Comments

These are the types of objects that are waitable:

change notification

console input

event

file

mutex

process

semaphore

thread

For console input handles, the wait will be satisfied when the input buffer becomes non-empty, i.e. at least one character is in the buffer.

See Also

Sleep, WaitForSingleObject