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

定义

任何提供的任务已完成时,创建将完成的任务。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.

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)

参数

tasks
IEnumerable<Task>

等待完成的任务。The tasks to wait on for completion.

返回

表示提供的任务之一已完成的任务。A task that represents the completion of one of the supplied tasks. 返回任务的结果是完成的任务。The return task's Result is the task that completed.

异常

tasks 参数为 nullThe tasks argument was null.

tasks 数组包含了 null 任务,或为空。The tasks array contained a null task, or was empty.

注解

当任何提供的任务完成时,将完成返回的任务。The returned task will complete when any of the supplied tasks has completed. 返回的任务将始终以RanToCompletion状态结束,并将其结果集设置为要完成的第一个任务。The returned task will always end in the RanToCompletion state with its Result set to the first task to complete. 即使完成的第一个任务以CanceledFaulted状态结束,也是如此。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)

参数

tasks
Task[]

等待完成的任务。The tasks to wait on for completion.

返回

表示提供的任务之一已完成的任务。A task that represents the completion of one of the supplied tasks. 返回任务的结果是完成的任务。The return task's Result is the task that completed.

异常

tasks 参数为 null。The tasks argument was null.

tasks 数组包含了 null 任务,或为空。The tasks array contained a null task, or was empty.

注解

当任何提供的任务完成时,将完成返回的任务。The returned task will complete when any of the supplied tasks has completed. 返回的任务将始终以其RanToCompletion Result设置为要完成的第一个任务的状态结束。The returned task will always end in the RanToCompletion state with its Result set to the first task to complete. 即使完成的第一个任务以CanceledFaulted状态结束,也是如此。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))

类型参数

TResult

已完成任务的类型。The type of the completed task.

参数

tasks
Task<TResult>[]

等待完成的任务。The tasks to wait on for completion.

返回

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.

异常

tasks 参数为 null。The tasks argument was null.

tasks 数组包含了 null 任务,或为空。The tasks array contained a null task, or was empty.

注解

当任何提供的任务完成时,将完成返回的任务。The returned task will complete when any of the supplied tasks has completed. 返回的任务将始终以 RanToCompletion 状态结束,并将其结果集设置为要完成的第一个任务。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))

类型参数

TResult

已完成任务的类型。The type of the completed task.

参数

tasks
IEnumerable<Task<TResult>>

等待完成的任务。The tasks to wait on for completion.

返回

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.

异常

tasks 参数为 nullThe tasks argument was null.

tasks 数组包含了 null 任务,或为空。The tasks array contained a null task, or was empty.

注解

当任何提供的任务完成时,将完成返回的任务。The returned task will complete when any of the supplied tasks has completed. 返回的任务将始终以 RanToCompletion 状态结束,并将其结果集设置为要完成的第一个任务。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.

适用于