Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Task.WhenAny(TResult) Method (Task(TResult)[])

.NET Framework 4.6 and 4.5

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

Namespace:  System.Threading.Tasks
Assemblies:   System.Threading.Tasks (in System.Threading.Tasks.dll)
  mscorlib (in mscorlib.dll)

static member WhenAny : 
        tasks:Task<'TResult>[] -> Task<Task<'TResult>> 

Type Parameters

TResult

The type of the completed task.

Parameters

tasks
Type: System.Threading.Tasks.Task(TResult)[]

The tasks to wait on for completion.

Return Value

Type: System.Threading.Tasks.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.

ExceptionCondition
ArgumentNullException

The tasks argument was null.

ArgumentException

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

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.

.NET Framework

Supported in: 4.6, 4.5

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft