Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有一系列任务,Task[]. 如何编写仅在数组中的一个或多个任务失败(或被取消)时运行的延续?
我认为您应该查看在为任务 设置延续时可以指定的延续选项。
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());