Task.WaitAny Method

Definition

Waits for any of the provided Task objects to complete execution.

Overloads

Name Description
WaitAny(Task[], TimeSpan)

Waits for any of the provided Task objects to complete execution within a specified time interval.

WaitAny(Task[], Int32, CancellationToken)

Waits for any of the provided Task objects to complete execution within a specified number of milliseconds or until a cancellation token is cancelled.

WaitAny(Task[], Int32)

Waits for any of the provided Task objects to complete execution within a specified number of milliseconds.

WaitAny(Task[], CancellationToken)

Waits for any of the provided Task objects to complete execution unless the wait is cancelled.

WaitAny(Task[])

Waits for any of the provided Task objects to complete execution.

WaitAny(Task[], TimeSpan)

Source:
Task.cs
Source:
Task.cs
Source:
Task.cs
Source:
Task.cs
Source:
Task.cs

Waits for any of the provided Task objects to complete execution within a specified time interval.

public:
 static int WaitAny(cli::array <System::Threading::Tasks::Task ^> ^ tasks, TimeSpan timeout);
public static int WaitAny(System.Threading.Tasks.Task[] tasks, TimeSpan timeout);
static member WaitAny : System.Threading.Tasks.Task[] * TimeSpan -> int
Public Shared Function WaitAny (tasks As Task(), timeout As TimeSpan) As Integer

Parameters

tasks
Task[]

An array of Task instances on which to wait.

timeout
TimeSpan

A TimeSpan that represents the number of milliseconds to wait, or a TimeSpan that represents -1 milliseconds to wait indefinitely.

Returns

The index of the completed task in the tasks array argument, or -1 if the timeout occurred.

Exceptions

The Task has been disposed.

The tasks argument is null.

The TotalMilliseconds property of the timeout argument is a negative number other than -1, which represents an infinite time-out.

-or-

The TotalMilliseconds property of the timeout argument is greater than Int32.MaxValue.

The tasks argument contains a null element.

Applies to

WaitAny(Task[], Int32, CancellationToken)

Source:
Task.cs
Source:
Task.cs
Source:
Task.cs
Source:
Task.cs
Source:
Task.cs

Waits for any of the provided Task objects to complete execution within a specified number of milliseconds or until a cancellation token is cancelled.

public:
 static int WaitAny(cli::array <System::Threading::Tasks::Task ^> ^ tasks, int millisecondsTimeout, System::Threading::CancellationToken cancellationToken);
public static int WaitAny(System.Threading.Tasks.Task[] tasks, int millisecondsTimeout, System.Threading.CancellationToken cancellationToken);
static member WaitAny : System.Threading.Tasks.Task[] * int * System.Threading.CancellationToken -> int
Public Shared Function WaitAny (tasks As Task(), millisecondsTimeout As Integer, cancellationToken As CancellationToken) As Integer

Parameters

tasks
Task[]

An array of Task instances on which to wait.

millisecondsTimeout
Int32

The number of milliseconds to wait, or Infinite (-1) to wait indefinitely.

cancellationToken
CancellationToken

A CancellationToken to observe while waiting for a task to complete.

Returns

The index of the completed task in the tasks array argument, or -1 if the timeout occurred.

Exceptions

The Task has been disposed.

The tasks argument is null.