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.

適用於