The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

WaitHandle.WaitAny Method (WaitHandle[])

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)

public static int WaitAny(
	WaitHandle[] waitHandles


Type: System.Threading.WaitHandle []
An array that contains the objects for which the current instance will wait.

Return Value

Type: System.Int32
The array index of the object that satisfied the wait.


The waitHandles parameter is null.


One or more of the objects in the waitHandles array is null.


The number of objects in waitHandles is greater than the system permits.


waitHandles is an array with no elements.

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.

Calling this method overload is equivalent to calling the WaitAny(WaitHandle[], Int32) method overload and specifying -1 (or Timeout.Infinite) for millisecondsTimeout.

The following example demonstrates how to call the WaitAny method to wait for the first of several threads to finish.

This code is part of a larger example provided for the WaitAll(WaitHandle[]) method overload.

// Wait for ANY subtask to complete.

// Create an array of ManualResetEvent wait handles. Each subtask will
// signal its ManualResetEvent when it is finished.
WaitHandle[] waitHandles = finished.ToArray();
int index = WaitHandle.WaitTimeout;

index = WaitHandle.WaitAny(waitHandles);

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone