TaskFactory.ContinueWhenAny 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
创建一个延续 Task,它将在提供的组中的任何任务完成后马上开始。
重载
ContinueWhenAny(Task[], Action<Task>, TaskContinuationOptions)
创建一个延续 Task,它将在提供的组中的任何任务完成后马上开始。
public:
System::Threading::Tasks::Task ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Action<System::Threading::Tasks::Task ^> ^ continuationAction, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task ContinueWhenAny (System.Threading.Tasks.Task[] tasks, Action<System.Threading.Tasks.Task> continuationAction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
member this.ContinueWhenAny : System.Threading.Tasks.Task[] * Action<System.Threading.Tasks.Task> * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task
Public Function ContinueWhenAny (tasks As Task(), continuationAction As Action(Of Task), continuationOptions As TaskContinuationOptions) As Task
参数
- tasks
- Task[]
在一个任务完成时继续执行的任务所在的数组。
- continuationOptions
- TaskContinuationOptions
TaskContinuationOptions 值,用于控制所创建的延续 Task 的行为。
返回
新的延续 Task。
例外
已释放 tasks
数组中的一个元素。
continuationOptions
指定了无效的 TaskContinuationOptions 值。
注解
NotOn* 和 OnlyOn*TaskContinuationOptions(约束TaskStatus将执行延续)是非法的ContinueWhenAny
。
另请参阅
适用于
ContinueWhenAny(Task[], Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler)
创建一个延续 Task,它将在提供的组中的任何任务完成后马上开始。
public:
System::Threading::Tasks::Task ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Action<System::Threading::Tasks::Task ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task ContinueWhenAny (System.Threading.Tasks.Task[] tasks, Action<System.Threading.Tasks.Task> continuationAction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWhenAny : System.Threading.Tasks.Task[] * Action<System.Threading.Tasks.Task> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task
Public Function ContinueWhenAny (tasks As Task(), continuationAction As Action(Of Task), cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task
参数
- tasks
- Task[]
在一个任务完成时继续执行的任务所在的数组。
- cancellationToken
- CancellationToken
将指派给新的延续任务的 CancellationToken。
- continuationOptions
- TaskContinuationOptions
TaskContinuationOptions 值,用于控制所创建的延续 Task 的行为。
- scheduler
- TaskScheduler
用于计划所创建的延续 TaskScheduler 的 Task。
返回
新的延续 Task。
例外
tasks
数组为 null
。
或 -
continuationAction
上声明的默认值为null
。或 -
scheduler
上声明的默认值为null
。
continuationOptions
指定了无效的 TaskContinuationOptions 值。
注解
NotOn 和 OnlyOn**TaskContinuationOptions(约束TaskStatus将对其执行延续)是非法的。ContinueWhenAny
另请参阅
适用于
ContinueWhenAny(Task[], Action<Task>)
创建一个延续 Task,它将在提供的组中的任何任务完成后马上开始。
public:
System::Threading::Tasks::Task ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Action<System::Threading::Tasks::Task ^> ^ continuationAction);
public System.Threading.Tasks.Task ContinueWhenAny (System.Threading.Tasks.Task[] tasks, Action<System.Threading.Tasks.Task> continuationAction);
member this.ContinueWhenAny : System.Threading.Tasks.Task[] * Action<System.Threading.Tasks.Task> -> System.Threading.Tasks.Task
Public Function ContinueWhenAny (tasks As Task(), continuationAction As Action(Of Task)) As Task
参数
- tasks
- Task[]
在一个任务完成时继续执行的任务所在的数组。
返回
新的延续 Task。
例外
已释放 tasks
数组中的一个元素。
示例
以下示例演示如何使用 ContinueWhenAny
和 ContinueWhenAll
:
using System;
using System.Threading;
using System.Threading.Tasks;
class ContinueWhenMultiDemo
{
// Demonstrated features:
// Task.Factory
// TaskFactory.ContinueWhenAll()
// TaskFactory.ContinueWhenAny()
// Task.Wait()
// Expected results:
// Three tasks are created in parallel.
// Each task for a different period of time prints a number and returns it.
// A ContinueWhenAny() task indicates the first of the three tasks to complete.
// A ContinueWhenAll() task sums up the results of the three tasks and prints out the total.
// Documentation:
// http://msdn.microsoft.com/library/system.threading.tasks.taskfactory_members(VS.100).aspx
static void Main()
{
// Schedule a list of tasks that return integer
Task<int>[] tasks = new Task<int>[]
{
Task<int>.Factory.StartNew(() =>
{
Thread.Sleep(500);
Console.WriteLine("Task={0}, Thread={1}, x=5", Task.CurrentId, Thread.CurrentThread.ManagedThreadId);
return 5;
}),
Task<int>.Factory.StartNew(() =>
{
Thread.Sleep(10);
Console.WriteLine("Task={0}, Thread={1}, x=3", Task.CurrentId, Thread.CurrentThread.ManagedThreadId);
return 3;
}),
Task<int>.Factory.StartNew(() =>
{
Thread.Sleep(200);
Console.WriteLine("Task={0}, Thread={1}, x=2", Task.CurrentId, Thread.CurrentThread.ManagedThreadId);
return 2;
})
};
// Schedule a continuation to indicate the result of the first task to complete
Task.Factory.ContinueWhenAny(tasks, winner =>
{
// You would expect winning result = 3 on multi-core systems, because you expect
// tasks[1] to finish first.
Console.WriteLine("Task={0}, Thread={1} (ContinueWhenAny): Winning result = {2}", Task.CurrentId, Thread.CurrentThread.ManagedThreadId, winner.Result);
});
// Schedule a continuation that sums up the results of all tasks, then wait on it.
// The list of antecendent tasks is passed as an argument by the runtime.
Task.Factory.ContinueWhenAll(tasks,
(antecendents) =>
{
int sum = 0;
foreach (Task<int> task in antecendents)
{
sum += task.Result;
}
Console.WriteLine("Task={0}, Thread={1}, (ContinueWhenAll): Total={2} (expected 10)", Task.CurrentId, Thread.CurrentThread.ManagedThreadId, sum);
})
.Wait();
}
}
Imports System.Threading
Imports System.Threading.Tasks
Module ContinuationWhenMulti
' Demonstrated features:
' Task.Factory
' TaskFactory.ContinueWhenAll()
' TaskFactory.ContinueWhenAny()
' Task.Wait()
' Expected results:
' Three tasks are created in parallel.
' Each task for a different period of time prints a number and returns it.
' A ContinueWhenAny() task indicates the first of the three tasks to complete.
' A ContinueWhenAll() task sums up the results of the three tasks and prints out the total.
' Documentation:
' http://msdn.microsoft.com/library/system.threading.tasks.taskfactory_members(VS.100).aspx
Sub Main()
' Schedule a list of tasks that return integer
Dim tasks As Task(Of Integer)() = New Task(Of Integer)() {
Task(Of Integer).Factory.StartNew(Function()
Thread.Sleep(500)
Console.WriteLine("Task={0}, Thread={1}, x=5", Task.CurrentId, Thread.CurrentThread.ManagedThreadId)
Return 5
End Function),
Task(Of Integer).Factory.StartNew(Function()
Thread.Sleep(10)
Console.WriteLine("Task={0}, Thread={1}, x=3", Task.CurrentId, Thread.CurrentThread.ManagedThreadId)
Return 3
End Function),
Task(Of Integer).Factory.StartNew(Function()
Thread.Sleep(200)
Console.WriteLine("Task={0}, Thread={1}, x=2", Task.CurrentId, Thread.CurrentThread.ManagedThreadId)
Return 2
End Function)}
' Schedule a continuation to indicate the result of the first task to complete
Task.Factory.ContinueWhenAny(tasks, Sub(winner)
' You would expect winning result = 3 on multi-core systems, because you expect
' tasks[1] to finish first.
Console.WriteLine("Task={0}, Thread={1} (ContinueWhenAny): Winning result = {2}", Task.CurrentId, Thread.CurrentThread.ManagedThreadId, winner.Result)
End Sub)
' Schedule a continuation that sums up the results of all tasks, then wait on it.
' The list of antecendent tasks is passed as an argument by the runtime.
Task.Factory.ContinueWhenAll(tasks, Sub(antecendents)
Dim sum As Integer = 0
For Each task__1 As Task(Of Integer) In antecendents
sum += task__1.Result
Next
Console.WriteLine("Task={0}, Thread={1}, (ContinueWhenAll): Total={2} (expected 10)", Task.CurrentId, Thread.CurrentThread.ManagedThreadId, sum)
End Sub).Wait()
End Sub
End Module
另请参阅
适用于
ContinueWhenAny(Task[], Action<Task>, CancellationToken)
创建一个延续 Task,它将在提供的组中的任何任务完成后马上开始。
public:
System::Threading::Tasks::Task ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Action<System::Threading::Tasks::Task ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task ContinueWhenAny (System.Threading.Tasks.Task[] tasks, Action<System.Threading.Tasks.Task> continuationAction, System.Threading.CancellationToken cancellationToken);
member this.ContinueWhenAny : System.Threading.Tasks.Task[] * Action<System.Threading.Tasks.Task> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function ContinueWhenAny (tasks As Task(), continuationAction As Action(Of Task), cancellationToken As CancellationToken) As Task
参数
- tasks
- Task[]
在一个任务完成时继续执行的任务所在的数组。
- cancellationToken
- CancellationToken
将指派给新的延续任务的 CancellationToken。
返回
新的延续 Task。
例外
另请参阅
适用于
ContinueWhenAny<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>,TResult>, TaskContinuationOptions)
创建一个延续 Task<TResult>,它将在提供的组中的任何任务完成后马上开始。
public:
generic <typename TAntecedentResult, typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Func<System::Threading::Tasks::Task<TAntecedentResult> ^, TResult> ^ continuationFunction, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TAntecedentResult,TResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Func<System.Threading.Tasks.Task<TAntecedentResult>,TResult> continuationFunction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
member this.ContinueWhenAny : System.Threading.Tasks.Task<'AntecedentResult>[] * Func<System.Threading.Tasks.Task<'AntecedentResult>, 'Result> * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAny(Of TAntecedentResult, TResult) (tasks As Task(Of TAntecedentResult)(), continuationFunction As Func(Of Task(Of TAntecedentResult), TResult), continuationOptions As TaskContinuationOptions) As Task(Of TResult)
类型参数
- TAntecedentResult
以前的 tasks
结果的类型。
- TResult
由 continuationFunction
委托返回并与创建的 Task<TResult> 关联的结果的类型。
参数
- tasks
- Task<TAntecedentResult>[]
在一个任务完成时继续执行的任务所在的数组。
- continuationOptions
- TaskContinuationOptions
TaskContinuationOptions 值,用于控制所创建的延续 Task<TResult> 的行为。
返回
新的延续 Task<TResult>。
例外
已释放 tasks
数组中的一个元素。
continuationOptions
指定了无效的 TaskContinuationOptions 值。
注解
NotOn 和 OnlyOn**TaskContinuationOptions(约束TaskStatus将对其执行延续)是非法的。ContinueWhenAny
另请参阅
适用于
ContinueWhenAny<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>,TResult>)
创建一个延续 Task<TResult>,它将在提供的组中的任何任务完成后马上开始。
public:
generic <typename TAntecedentResult, typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Func<System::Threading::Tasks::Task<TAntecedentResult> ^, TResult> ^ continuationFunction);
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TAntecedentResult,TResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Func<System.Threading.Tasks.Task<TAntecedentResult>,TResult> continuationFunction);
member this.ContinueWhenAny : System.Threading.Tasks.Task<'AntecedentResult>[] * Func<System.Threading.Tasks.Task<'AntecedentResult>, 'Result> -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAny(Of TAntecedentResult, TResult) (tasks As Task(Of TAntecedentResult)(), continuationFunction As Func(Of Task(Of TAntecedentResult), TResult)) As Task(Of TResult)
类型参数
- TAntecedentResult
以前的 tasks
结果的类型。
- TResult
由 continuationFunction
委托返回并与创建的 Task<TResult> 关联的结果的类型。
参数
- tasks
- Task<TAntecedentResult>[]
在一个任务完成时继续执行的任务所在的数组。
返回
新的延续 Task<TResult>。
例外
已释放 tasks
数组中的一个元素。
另请参阅
适用于
ContinueWhenAny<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>,TResult>, CancellationToken)
创建一个延续 Task<TResult>,它将在提供的组中的任何任务完成后马上开始。
public:
generic <typename TAntecedentResult, typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Func<System::Threading::Tasks::Task<TAntecedentResult> ^, TResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TAntecedentResult,TResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Func<System.Threading.Tasks.Task<TAntecedentResult>,TResult> continuationFunction, System.Threading.CancellationToken cancellationToken);
member this.ContinueWhenAny : System.Threading.Tasks.Task<'AntecedentResult>[] * Func<System.Threading.Tasks.Task<'AntecedentResult>, 'Result> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAny(Of TAntecedentResult, TResult) (tasks As Task(Of TAntecedentResult)(), continuationFunction As Func(Of Task(Of TAntecedentResult), TResult), cancellationToken As CancellationToken) As Task(Of TResult)
类型参数
- TAntecedentResult
以前的 tasks
结果的类型。
- TResult
由 continuationFunction
委托返回并与创建的 Task<TResult> 关联的结果的类型。
参数
- tasks
- Task<TAntecedentResult>[]
在一个任务完成时继续执行的任务所在的数组。
- cancellationToken
- CancellationToken
将指派给新的延续任务的 CancellationToken。
返回
新的延续 Task<TResult>。
例外
另请参阅
适用于
ContinueWhenAny<TAntecedentResult,TResult>(Task<TAntecedentResult>[], Func<Task<TAntecedentResult>,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)
创建一个延续 Task<TResult>,它将在提供的组中的任何任务完成后马上开始。
public:
generic <typename TAntecedentResult, typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Func<System::Threading::Tasks::Task<TAntecedentResult> ^, TResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TAntecedentResult,TResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Func<System.Threading.Tasks.Task<TAntecedentResult>,TResult> continuationFunction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWhenAny : System.Threading.Tasks.Task<'AntecedentResult>[] * Func<System.Threading.Tasks.Task<'AntecedentResult>, 'Result> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAny(Of TAntecedentResult, TResult) (tasks As Task(Of TAntecedentResult)(), continuationFunction As Func(Of Task(Of TAntecedentResult), TResult), cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task(Of TResult)
类型参数
- TAntecedentResult
以前的 tasks
结果的类型。
- TResult
由 continuationFunction
委托返回并与创建的 Task<TResult> 关联的结果的类型。
参数
- tasks
- Task<TAntecedentResult>[]
在一个任务完成时继续执行的任务所在的数组。
- cancellationToken
- CancellationToken
将指派给新的延续任务的 CancellationToken。
- continuationOptions
- TaskContinuationOptions
TaskContinuationOptions 值,用于控制所创建的延续 Task<TResult> 的行为。
- scheduler
- TaskScheduler
用于计划所创建的延续 TaskScheduler 的 Task<TResult>。
返回
新的延续 Task<TResult>。
例外
tasks
数组为 null
。
或 -
continuationFunction
上声明的默认值为null
。或 -
scheduler
上声明的默认值为null
。
continuationOptions
指定了无效的 TaskContinuationOptions 值。
注解
NotOn 和 OnlyOn**TaskContinuationOptions(约束TaskStatus将对其执行延续)是非法的。ContinueWhenAny
另请参阅
适用于
ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>)
创建一个延续 Task,它将在提供的组中的任何任务完成后马上开始。
public:
generic <typename TAntecedentResult>
System::Threading::Tasks::Task ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Action<System::Threading::Tasks::Task<TAntecedentResult> ^> ^ continuationAction);
public System.Threading.Tasks.Task ContinueWhenAny<TAntecedentResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Action<System.Threading.Tasks.Task<TAntecedentResult>> continuationAction);
member this.ContinueWhenAny : System.Threading.Tasks.Task<'AntecedentResult>[] * Action<System.Threading.Tasks.Task<'AntecedentResult>> -> System.Threading.Tasks.Task
Public Function ContinueWhenAny(Of TAntecedentResult) (tasks As Task(Of TAntecedentResult)(), continuationAction As Action(Of Task(Of TAntecedentResult))) As Task
类型参数
- TAntecedentResult
以前的 tasks
结果的类型。
参数
- tasks
- Task<TAntecedentResult>[]
在一个任务完成时继续执行的任务所在的数组。
返回
新的延续 Task。
例外
已释放 tasks
数组中的一个元素。
另请参阅
适用于
ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>, CancellationToken)
创建一个延续 Task,它将在提供的组中的任何任务完成后马上开始。
public:
generic <typename TAntecedentResult>
System::Threading::Tasks::Task ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Action<System::Threading::Tasks::Task<TAntecedentResult> ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task ContinueWhenAny<TAntecedentResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Action<System.Threading.Tasks.Task<TAntecedentResult>> continuationAction, System.Threading.CancellationToken cancellationToken);
member this.ContinueWhenAny : System.Threading.Tasks.Task<'AntecedentResult>[] * Action<System.Threading.Tasks.Task<'AntecedentResult>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function ContinueWhenAny(Of TAntecedentResult) (tasks As Task(Of TAntecedentResult)(), continuationAction As Action(Of Task(Of TAntecedentResult)), cancellationToken As CancellationToken) As Task
类型参数
- TAntecedentResult
以前的 tasks
结果的类型。
参数
- tasks
- Task<TAntecedentResult>[]
在一个任务完成时继续执行的任务所在的数组。
- cancellationToken
- CancellationToken
将指派给新的延续任务的 CancellationToken。
返回
新的延续 Task。
例外
另请参阅
适用于
ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>, TaskContinuationOptions)
创建一个延续 Task,它将在提供的组中的任何任务完成后马上开始。
public:
generic <typename TAntecedentResult>
System::Threading::Tasks::Task ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Action<System::Threading::Tasks::Task<TAntecedentResult> ^> ^ continuationAction, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task ContinueWhenAny<TAntecedentResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Action<System.Threading.Tasks.Task<TAntecedentResult>> continuationAction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
member this.ContinueWhenAny : System.Threading.Tasks.Task<'AntecedentResult>[] * Action<System.Threading.Tasks.Task<'AntecedentResult>> * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task
Public Function ContinueWhenAny(Of TAntecedentResult) (tasks As Task(Of TAntecedentResult)(), continuationAction As Action(Of Task(Of TAntecedentResult)), continuationOptions As TaskContinuationOptions) As Task
类型参数
- TAntecedentResult
以前的 tasks
结果的类型。
参数
- tasks
- Task<TAntecedentResult>[]
在一个任务完成时继续执行的任务所在的数组。
- continuationOptions
- TaskContinuationOptions
TaskContinuationOptions 值,用于控制所创建的延续 Task 的行为。
返回
新的延续 Task。
例外
已释放 tasks
数组中的一个元素。
continuationOptions
指定了无效的 TaskContinuationOptions 值。
注解
NotOn 和 OnlyOn**TaskContinuationOptions(约束TaskStatus将对其执行延续)是非法的。ContinueWhenAny
另请参阅
适用于
ContinueWhenAny<TAntecedentResult>(Task<TAntecedentResult>[], Action<Task<TAntecedentResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler)
创建一个延续 Task,它将在提供的组中的任何任务完成后马上开始。
public:
generic <typename TAntecedentResult>
System::Threading::Tasks::Task ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task<TAntecedentResult> ^> ^ tasks, Action<System::Threading::Tasks::Task<TAntecedentResult> ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task ContinueWhenAny<TAntecedentResult> (System.Threading.Tasks.Task<TAntecedentResult>[] tasks, Action<System.Threading.Tasks.Task<TAntecedentResult>> continuationAction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWhenAny : System.Threading.Tasks.Task<'AntecedentResult>[] * Action<System.Threading.Tasks.Task<'AntecedentResult>> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task
Public Function ContinueWhenAny(Of TAntecedentResult) (tasks As Task(Of TAntecedentResult)(), continuationAction As Action(Of Task(Of TAntecedentResult)), cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task
类型参数
- TAntecedentResult
以前的 tasks
结果的类型。
参数
- tasks
- Task<TAntecedentResult>[]
在一个任务完成时继续执行的任务所在的数组。
- cancellationToken
- CancellationToken
将指派给新的延续任务的 CancellationToken。
- continuationOptions
- TaskContinuationOptions
TaskContinuationOptions 值,用于控制所创建的延续 Task 的行为。
- scheduler
- TaskScheduler
用于计划所创建的延续 TaskScheduler 的 Task<TResult>。
返回
新的延续 Task。
例外
tasks
数组为 null
。
或 -
continuationAction
上声明的默认值为null
。或 - paramref name="scheduler" /> 为
null
。
continuationOptions
指定了一个无效的 TaskContinuationOptions 值。
注解
NotOn 和 OnlyOn**TaskContinuationOptions(约束TaskStatus将对其执行延续)是非法的。ContinueWhenAny
另请参阅
适用于
ContinueWhenAny<TResult>(Task[], Func<Task,TResult>)
创建一个延续 Task<TResult>,它将在提供的组中的任何任务完成后马上开始。
public:
generic <typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Func<System::Threading::Tasks::Task ^, TResult> ^ continuationFunction);
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TResult> (System.Threading.Tasks.Task[] tasks, Func<System.Threading.Tasks.Task,TResult> continuationFunction);
member this.ContinueWhenAny : System.Threading.Tasks.Task[] * Func<System.Threading.Tasks.Task, 'Result> -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAny(Of TResult) (tasks As Task(), continuationFunction As Func(Of Task, TResult)) As Task(Of TResult)
类型参数
- TResult
由 continuationFunction
委托返回并与创建的 Task<TResult> 关联的结果的类型。
参数
- tasks
- Task[]
在一个任务完成时继续执行的任务所在的数组。
返回
新的延续 Task<TResult>。
例外
已释放 tasks
数组中的一个元素。
另请参阅
适用于
ContinueWhenAny<TResult>(Task[], Func<Task,TResult>, CancellationToken)
创建一个延续 Task<TResult>,它将在提供的组中的任何任务完成后马上开始。
public:
generic <typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Func<System::Threading::Tasks::Task ^, TResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TResult> (System.Threading.Tasks.Task[] tasks, Func<System.Threading.Tasks.Task,TResult> continuationFunction, System.Threading.CancellationToken cancellationToken);
member this.ContinueWhenAny : System.Threading.Tasks.Task[] * Func<System.Threading.Tasks.Task, 'Result> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAny(Of TResult) (tasks As Task(), continuationFunction As Func(Of Task, TResult), cancellationToken As CancellationToken) As Task(Of TResult)
类型参数
- TResult
由 continuationFunction
委托返回并与创建的 Task<TResult> 关联的结果的类型。
参数
- tasks
- Task[]
在一个任务完成时继续执行的任务所在的数组。
- cancellationToken
- CancellationToken
将指派给新的延续任务的 CancellationToken。
返回
新的延续 Task<TResult>。
例外
另请参阅
适用于
ContinueWhenAny<TResult>(Task[], Func<Task,TResult>, TaskContinuationOptions)
创建一个延续 Task<TResult>,它将在提供的组中的任何任务完成后马上开始。
public:
generic <typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Func<System::Threading::Tasks::Task ^, TResult> ^ continuationFunction, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TResult> (System.Threading.Tasks.Task[] tasks, Func<System.Threading.Tasks.Task,TResult> continuationFunction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
member this.ContinueWhenAny : System.Threading.Tasks.Task[] * Func<System.Threading.Tasks.Task, 'Result> * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAny(Of TResult) (tasks As Task(), continuationFunction As Func(Of Task, TResult), continuationOptions As TaskContinuationOptions) As Task(Of TResult)
类型参数
- TResult
由 continuationFunction
委托返回并与创建的 Task<TResult> 关联的结果的类型。
参数
- tasks
- Task[]
在一个任务完成时继续执行的任务所在的数组。
- continuationOptions
- TaskContinuationOptions
TaskContinuationOptions 值,用于控制所创建的延续 Task<TResult> 的行为。
返回
新的延续 Task<TResult>。
例外
已释放 tasks
数组中的一个元素。
continuationOptions
指定了无效的 TaskContinuationOptions 值。
注解
NotOn 和 OnlyOn**TaskContinuationOptions(约束TaskStatus将对其执行延续)是非法的。ContinueWhenAny
另请参阅
适用于
ContinueWhenAny<TResult>(Task[], Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)
创建一个延续 Task<TResult>,它将在提供的组中的任何任务完成后马上开始。
public:
generic <typename TResult>
System::Threading::Tasks::Task<TResult> ^ ContinueWhenAny(cli::array <System::Threading::Tasks::Task ^> ^ tasks, Func<System::Threading::Tasks::Task ^, TResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TResult> ContinueWhenAny<TResult> (System.Threading.Tasks.Task[] tasks, Func<System.Threading.Tasks.Task,TResult> continuationFunction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWhenAny : System.Threading.Tasks.Task[] * Func<System.Threading.Tasks.Task, 'Result> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWhenAny(Of TResult) (tasks As Task(), continuationFunction As Func(Of Task, TResult), cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task(Of TResult)
类型参数
- TResult
由 continuationFunction
委托返回并与创建的 Task<TResult> 关联的结果的类型。
参数
- tasks
- Task[]
在一个任务完成时继续执行的任务所在的数组。
- cancellationToken
- CancellationToken
将指派给新的延续任务的 CancellationToken。
- continuationOptions
- TaskContinuationOptions
TaskContinuationOptions 值,用于控制所创建的延续 Task<TResult> 的行为。
- scheduler
- TaskScheduler
用于计划所创建的延续 TaskScheduler 的 Task<TResult>。
返回
新的延续 Task<TResult>。
例外
tasks
数组为 null
。
或 -
continuationFunction
上声明的默认值为null
。或 -
scheduler
上声明的默认值为null
。
continuationOptions
指定了无效的 TaskContinuationOptions 值。
注解
NotOn 和 OnlyOn**TaskContinuationOptions(约束TaskStatus将对其执行延续)是非法的。ContinueWhenAny