Task.WhenAny Task.WhenAny Task.WhenAny Task.WhenAny Method

Definition

Creates a task that will complete when any of the supplied tasks have completed.

Overloads

WhenAny(IEnumerable<Task>) WhenAny(IEnumerable<Task>) WhenAny(IEnumerable<Task>) WhenAny(IEnumerable<Task>)

Creates a task that will complete when any of the supplied tasks have completed.

WhenAny(Task[]) WhenAny(Task[]) WhenAny(Task[]) WhenAny(Task[])

Creates a task that will complete when any of the supplied tasks have completed.

WhenAny<TResult>(Task<TResult>[]) WhenAny<TResult>(Task<TResult>[]) WhenAny<TResult>(Task<TResult>[]) WhenAny<TResult>(Task<TResult>[])

Creates a task that will complete when any of the supplied tasks have completed.

WhenAny<TResult>(IEnumerable<Task<TResult>>) WhenAny<TResult>(IEnumerable<Task<TResult>>) WhenAny<TResult>(IEnumerable<Task<TResult>>) WhenAny<TResult>(IEnumerable<Task<TResult>>)

Creates a task that will complete when any of the supplied tasks have completed.

WhenAny(IEnumerable<Task>) WhenAny(IEnumerable<Task>) WhenAny(IEnumerable<Task>) WhenAny(IEnumerable<Task>)

Creates a task that will complete when any of the supplied tasks have completed.

public:
 static System::Threading::Tasks::Task<System::Threading::Tasks::Task ^> ^ WhenAny(System::Collections::Generic::IEnumerable<System::Threading::Tasks::Task ^> ^ tasks);
public static System.Threading.Tasks.Task<System.Threading.Tasks.Task> WhenAny (System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task> tasks);
static member WhenAny : seq<System.Threading.Tasks.Task> -> System.Threading.Tasks.Task<System.Threading.Tasks.Task>
Public Shared Function WhenAny (tasks As IEnumerable(Of Task)) As Task(Of Task)
Parameters
tasks
IEnumerable<Task>

The tasks to wait on for completion.

Returns

A task that represents the completion of one of the supplied tasks. The return task's Result is the task that completed.

Exceptions

The tasks array contained a null task, or was empty.

Remarks

The returned task will complete when any of the supplied tasks has completed. The returned task will always end in the RanToCompletion state with its Result set to the first task to complete. This is true even if the first task to complete ended in the Canceled or Faulted state.

WhenAny(Task[]) WhenAny(Task[]) WhenAny(Task[]) WhenAny(Task[])

Creates a task that will complete when any of the supplied tasks have completed.

public:
 static System::Threading::Tasks::Task<System::Threading::Tasks::Task ^> ^ WhenAny(... cli::array <System::Threading::Tasks::Task ^> ^ tasks);
public static System.Threading.Tasks.Task<System.Threading.Tasks.Task> WhenAny (params System.Threading.Tasks.Task[] tasks);
static member WhenAny : System.Threading.Tasks.Task[] -> System.Threading.Tasks.Task<System.Threading.Tasks.Task>
Public Shared Function WhenAny (ParamArray tasks As Task()) As Task(Of Task)
Parameters
tasks
Task[]

The tasks to wait on for completion.

Returns

A task that represents the completion of one of the supplied tasks. The return task's Result is the task that completed.

Exceptions

The tasks array contained a null task, or was empty.

Remarks

The returned task will complete when any of the supplied tasks has completed. The returned task will always end in the RanToCompletion state with its Result set to the first task to complete. This is true even if the first task to complete ended in the Canceled or Faulted state.

WhenAny<TResult>(Task<TResult>[]) WhenAny<TResult>(Task<TResult>[]) WhenAny<TResult>(Task<TResult>[]) WhenAny<TResult>(Task<TResult>[])

Creates a task that will complete when any of the supplied tasks have completed.

public:
generic <typename TResult>
 static System::Threading::Tasks::Task<System::Threading::Tasks::Task<TResult> ^> ^ WhenAny(... cli::array <System::Threading::Tasks::Task<TResult> ^> ^ tasks);
public static System.Threading.Tasks.Task<System.Threading.Tasks.Task<TResult>> WhenAny<TResult> (params System.Threading.Tasks.Task<TResult>[] tasks);
static member WhenAny : System.Threading.Tasks.Task<'Result>[] -> System.Threading.Tasks.Task<System.Threading.Tasks.Task<'Result>>
Public Shared Function WhenAny(Of TResult) (ParamArray tasks As Task(Of TResult)()) As Task(Of Task(Of TResult))
Type Parameters
TResult

The type of the completed task.

Parameters
tasks
Task<TResult>[]

The tasks to wait on for completion.

Returns
Task<Task<TResult>>

A task that represents the completion of one of the supplied tasks. The return task's Result is the task that completed.

Exceptions

The tasks array contained a null task, or was empty.

Remarks

The returned task will complete when any of the supplied tasks has completed. The returned task will always end in the RanToCompletion state with its Result set to the first task to complete. This is true even if the first task to complete ended in the Canceled or Faulted state.

WhenAny<TResult>(IEnumerable<Task<TResult>>) WhenAny<TResult>(IEnumerable<Task<TResult>>) WhenAny<TResult>(IEnumerable<Task<TResult>>) WhenAny<TResult>(IEnumerable<Task<TResult>>)

Creates a task that will complete when any of the supplied tasks have completed.

public:
generic <typename TResult>
 static System::Threading::Tasks::Task<System::Threading::Tasks::Task<TResult> ^> ^ WhenAny(System::Collections::Generic::IEnumerable<System::Threading::Tasks::Task<TResult> ^> ^ tasks);
public static System.Threading.Tasks.Task<System.Threading.Tasks.Task<TResult>> WhenAny<TResult> (System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task<TResult>> tasks);
static member WhenAny : seq<System.Threading.Tasks.Task<'Result>> -> System.Threading.Tasks.Task<System.Threading.Tasks.Task<'Result>>
Public Shared Function WhenAny(Of TResult) (tasks As IEnumerable(Of Task(Of TResult))) As Task(Of Task(Of TResult))
Type Parameters
TResult

The type of the completed task.

Parameters
tasks
IEnumerable<Task<TResult>>

The tasks to wait on for completion.

Returns
Task<Task<TResult>>

A task that represents the completion of one of the supplied tasks. The return task's Result is the task that completed.

Exceptions

The tasks array contained a null task, or was empty.

Remarks

The returned task will complete when any of the supplied tasks has completed. The returned task will always end in the RanToCompletion state with its Result set to the first task to complete. This is true even if the first task to complete ended in the Canceled or Faulted state.

Applies to