我现在尝试使用Task.Factory.ContinueWhenAll()几次,目的是仅在所有先行项运行完成且没有任何错误或取消时才调用延续。这样做会导致ArgumentOutOfRangeException与消息一起抛出,
排除多个任务的延续的特定延续类型是无效的。参数名称:continuationOptions
例如,代码
var first = Task.Factory.StartNew<MyResult>(
DoSomething,
firstInfo,
tokenSource.Token);
var second = Task.Factory.StartNew<MyResult>(
DoSomethingElse,
mystate,
tokenSource.Token);
var third = Task.Factory.ContinueWhenAll(
new[] { first, second },
DoSomethingNowThatFirstAndSecondAreDone,
tokenSource.Token,
TaskContinuationOptions.OnlyOnRanToCompletion, // not allowed!
TaskScheduler.FromCurrentSynchronizationContext());
TPL 不接受。有没有办法使用其他一些 TPL 方法来做这样的事情?