<分区>
我知道Task.WaitAll (Task1,Task2) 等待所有提供的任务对象完成执行。
Task.WhenAll 有什么用?
Task.WhenAll在 MSDN 中说
Creates a task that will complete when all of the supplied tasks have completed.
once 可以应用 Task.WhenAll() 的真实场景是什么
<分区>
我知道Task.WaitAll (Task1,Task2) 等待所有提供的任务对象完成执行。
Task.WhenAll 有什么用?
Task.WhenAll在 MSDN 中说
Creates a task that will complete when all of the supplied tasks have completed.
once 可以应用 Task.WhenAll() 的真实场景是什么
最佳答案
WaitAll
阻塞调用线程,而 WhenAll
提供了一个 promise 任务,您可以使用 async-await< 来异步等待
同时不浪费线程:
async Task ProcessAsync()
{
await Task.WhenAll(DownloadAsync(), IntializeParserAsync(),...);
}
您应该在任何需要等待的地方使用WhenAll
,而不必阻塞线程,这样可以提高可伸缩性。 (阅读:几乎任何地方)
关于c# - Task.WhenAll - 何时使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24809911/