This documentation is archived and is not being maintained.

WaitHandle.WaitAny Method (WaitHandle[])

.NET Framework 1.1

Waits for any of the elements in the specified array to receive a signal.

[Visual Basic]
Overloads Public Shared Function WaitAny( _
   ByVal waitHandles() As WaitHandle _
) As Integer
[C#]
public static int WaitAny(
 WaitHandle[] waitHandles
);
[C++]
public: static int WaitAny(
 WaitHandle* waitHandles[]
);
[JScript]
public static function WaitAny(
   waitHandles : WaitHandle[]
) : int;

Parameters

waitHandles
A WaitHandle array containing the objects for which the current instance will wait.

Return Value

The array index of the object that satisfied the wait.

Exceptions

Exception Type Condition
ArgumentNullException The waitHandles parameter is a null reference (Nothing in Visual Basic) or one or more of the objects in the waitHandles array is a null reference (Nothing).
NotSupportedException The number of objects in waitHandles is greater than the system permits.
ApplicationException waitHandles is an array with no elements.

Remarks

This method returns when any handle is signaled. If more than one object becomes signaled during the call, the return value is the array index of the signaled object with the smallest index value of all the signaled objects. On some implementations, if more that 64 handles are passed, a NotSupportedException is thrown. If the array contains duplicates, the call will fail.

Note   If a thread exits or aborts without explicitly releasing a Mutex, and that Mutex is included in a WaitAny on another thread, the index returned by WaitAny will be the correct value plus 128. To guard against this, check the index before using it, with C# code such as if (index >= 128) index -= 128; or Visual Basic code such as If index >= 128 Then index -= 128.

Calling this overload is equivalent to calling the WaitAny(WaitHandle[],Int32,Boolean) overload, specifying -1 or Timeout.Infinite for the second parameter and false for the third parameter.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

WaitHandle Class | WaitHandle Members | System.Threading Namespace | WaitHandle.WaitAny Overload List

Show: