Task.WaitAny method (1 of 5)

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

public static int WaitAny(params Task[] tasks)
parameter description
tasks The tasks to wait for completion.

Return Value

The index of the completed task in the tasks array.

See Also


Task.WaitAny method (2 of 5)

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

public static int WaitAny(Task[] tasks, CancellationToken cancellationToken)
parameter description
tasks The tasks to wait for completion.
cancellationToken Cancellation token that can be used to cancel the wait.

Return Value

The index of the completed task in the tasks array.

See Also


Task.WaitAny method (3 of 5)

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

public static int WaitAny(Task[] tasks, int millisecondsTimeout)
parameter description
tasks The tasks to wait for completion.
millisecondsTimeout The number of milliseconds to wait, or -1 to wait indefinitely.

Return Value

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

See Also


Task.WaitAny method (4 of 5)

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

public static int WaitAny(Task[] tasks, TimeSpan timeout)
parameter description
tasks The tasks to wait for completion.
timeout A time span that represents the number of milliseconds to wait, or TimeSpan.FromMilliseconds(-1) to wait indefinitely.

Return Value

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

See Also


Task.WaitAny method (5 of 5)

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(Task[] tasks, int millisecondsTimeout, 
    CancellationToken cancellationToken)
parameter description
tasks The tasks to wait for completion.
millisecondsTimeout The number of milliseconds to wait, or -1 to wait indefinitely.
cancellationToken Cancellation token that can be used to cancel the wait.

Return Value

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

See Also