【问题标题】:Continuation when one or more tasks in an array is cancelled or fails?当阵列中的一个或多个任务被取消或失败时继续?
【发布时间】:2012-02-11 06:26:05
【问题描述】:

如果我有一个任务数组,Task[]。如何编写仅在数组中的一个或多个任务失败(或被取消)时运行的延续?

【问题讨论】:

    标签: c# task continuation


    【解决方案1】:

    我认为您应该查看continuation options,您可以在set the continuation 执行任务时指定该set the continuation

    Task<int> [] tasks = new Task<int>[5];
    // Add tasks...
    
    foreach (var task in tasks)
    {
        task.ContinueWith(a => a.Id, TaskContinuationOptions.OnlyOnCanceled);
    }
    Task.WaitAny(tasks, new CancellationToken());
    

    【讨论】:

      猜你喜欢
      • 2020-06-13
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 2013-02-13
      • 1970-01-01
      • 2012-12-28
      • 2017-01-30
      相关资源
      最近更新 更多