Creates a task that will complete when any of the supplied tasks have completed.
Overloads WhenAny(Task, Task)Creates a task that will complete when either of the supplied tasks have completed.
public:
static System::Threading::Tasks::Task<System::Threading::Tasks::Task ^> ^ WhenAny(System::Threading::Tasks::Task ^ task1, System::Threading::Tasks::Task ^ task2);
public static System.Threading.Tasks.Task<System.Threading.Tasks.Task> WhenAny(System.Threading.Tasks.Task task1, System.Threading.Tasks.Task task2);
static member WhenAny : System.Threading.Tasks.Task * System.Threading.Tasks.Task -> System.Threading.Tasks.Task<System.Threading.Tasks.Task>
Public Shared Function WhenAny (task1 As Task, task2 As Task) As Task(Of Task)
Parameters
The first task to wait on for completion.
The second task to wait on for completion.
ReturnsA new task that represents the completion of one of the supplied tasks. Its Result
is the task that completed first.
The returned task completes when any of the supplied tasks has completed. The returned task always ends 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.
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
The tasks to wait on for completion.
ReturnsA task that represents the completion of one of the supplied tasks. The return task's Result is the task that completed.
ExceptionsThe 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.
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(ReadOnlySpan<System::Threading::Tasks::Task ^> tasks);
public static System.Threading.Tasks.Task<System.Threading.Tasks.Task> WhenAny(scoped ReadOnlySpan<System.Threading.Tasks.Task> tasks);
static member WhenAny : ReadOnlySpan<System.Threading.Tasks.Task> -> System.Threading.Tasks.Task<System.Threading.Tasks.Task>
Public Shared Function WhenAny (tasks As ReadOnlySpan(Of Task)) As Task(Of Task)
Parameters Returns
A task that represents the completion of one of the supplied tasks. The return Task's Result is the task that completed.
ExceptionsThe tasks
array contains a null
task, or is 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.
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 Returns
A task that represents the completion of one of the supplied tasks. The return task's Result is the task that completed.
ExceptionsThe 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.
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
The type of the completed task.
Parameters ReturnsA task that represents the completion of one of the supplied tasks. The return task's Result is the task that completed.
ExceptionsThe 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.
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(ReadOnlySpan<System::Threading::Tasks::Task<TResult> ^> tasks);
public static System.Threading.Tasks.Task<System.Threading.Tasks.Task<TResult>> WhenAny<TResult>(scoped ReadOnlySpan<System.Threading.Tasks.Task<TResult>> tasks);
static member WhenAny : ReadOnlySpan<System.Threading.Tasks.Task<'Result>> -> System.Threading.Tasks.Task<System.Threading.Tasks.Task<'Result>>
Public Shared Function WhenAny(Of TResult) (tasks As ReadOnlySpan(Of Task(Of TResult))) As Task(Of Task(Of TResult))
Type Parameters
The type of the result returned by the tasks.
Parameters ReturnsA task that represents the completion of one of the supplied tasks. The return Task's Result is the task that completed.
ExceptionsThe tasks
array contains a null
task, or is 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.
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
The type of the completed task.
ParametersThe tasks to wait on for completion.
ReturnsA task that represents the completion of one of the supplied tasks. The return task's Result is the task that completed.
ExceptionsThe 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.
Creates a task that will complete when either of the supplied tasks have completed.
public:
generic <typename TResult>
static System::Threading::Tasks::Task<System::Threading::Tasks::Task<TResult> ^> ^ WhenAny(System::Threading::Tasks::Task<TResult> ^ task1, System::Threading::Tasks::Task<TResult> ^ task2);
public static System.Threading.Tasks.Task<System.Threading.Tasks.Task<TResult>> WhenAny<TResult>(System.Threading.Tasks.Task<TResult> task1, System.Threading.Tasks.Task<TResult> task2);
static member WhenAny : System.Threading.Tasks.Task<'Result> * System.Threading.Tasks.Task<'Result> -> System.Threading.Tasks.Task<System.Threading.Tasks.Task<'Result>>
Public Shared Function WhenAny(Of TResult) (task1 As Task(Of TResult), task2 As Task(Of TResult)) As Task(Of Task(Of TResult))
Type Parameters
The type of the result of the returned task.
Parameters ReturnsA task that represents the completion of one of the supplied tasks. The returned task's TResult
is the task that completed first.
The returned task completes when any of the supplied tasks has completed. The returned task always ends 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.
Tip
In every overload of Task.WhenAny(), when the method returns the first completed task, the other tasks will continue running until completion, even if any of them completed in the Canceled
or Faulted
state. If that behavior is undesirable, you can cancel all the remaining tasks once the first task completes.
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide. In this articleWas this page helpful?
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4