WhenAny(TResult) Method (IEnumerable(Task(TResult)))

Task.WhenAny<'TResult> Method (IEnumerable<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
Assembly:  mscorlib (in mscorlib.dll)

static member WhenAny<'TResult> : 
        tasks:IEnumerable<Task<'TResult>> -> Task<Task<'TResult>>


Type: System.Collections.Generic.IEnumerable<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.

Type Parameters


The type of the completed task.

Exception Condition

The tasks argument was null.


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.

Universal Windows Platform
Available since 4.5
.NET Framework
Available since 4.5
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
© 2015 Microsoft