.net 4.0 在A和B运行完成后,是否可以使用单个TPL方法在没有故障或取消的情况下继续执行任务C?

.net 4.0 在A和B运行完成后,是否可以使用单个TPL方法在没有故障或取消的情况下继续执行任务C?,.net-4.0,task,task-parallel-library,continuations,.net 4.0,Task,Task Parallel Library,Continuations,我已经尝试使用了几次Task.Factory.ContinueWhenAll(),目的是仅当所有先行项运行到完成时才调用一个continuation,而没有任何错误或取消。这样做会导致与消息一起抛出一个ArgumentOutOfRangeException 为多个任务的延续排除特定的延续类型是无效的。参数名称:continuationOptions 例如,代码 var first = Task.Factory.StartNew<MyResult>( DoSomething,

我已经尝试使用了几次Task.Factory.ContinueWhenAll(),目的是仅当所有先行项运行到完成时才调用一个continuation,而没有任何错误或取消。这样做会导致与消息一起抛出一个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());
var first=Task.Factory.StartNew(
DoSomething,
第一信息,
tokenSource.Token);
var second=Task.Factory.StartNew(
DoSomethingElse,
我的国家,
tokenSource.Token);
第三个变量=Task.Factory.continuewhell(
新[]{first,second},
第一次和第二次都没有完成的事情,
tokenSource.Token,
TaskContinuationOptions.OnlyOnRanToCompletion,//不允许!
TaskScheduler.FromCurrentSynchronizationContext());

第三方物流不可接受。有没有其他的第三方物流方法可以做到这一点?

似乎没有直接的方法。我通过将onlynortocompletion更改为None并检查传递到continuation中的每个任务的Exception是否非空来解决这个问题。差不多

private void DoSomethingNowThatFirstAndSecondAreDone(Task<MyResult>[] requestTasks)
{
    if (requestTasks.Any(t => t.Exception != null))
        return;

    // otherwise proceed...
}
private void dosomething未完成第一个和第二个任务(任务[]请求任务)
{
if(requestTasks.Any(t=>t.Exception!=null))
返回;
//否则继续。。。
}
工作正常,但这似乎不是一种非常令人满意的方法来处理具有多个先行项的案例,并使用单个案例Task.Factory.ContinueWith使用的模式中断