WaitAll vs WhenAll

后端 未结 4 1926
夕颜
夕颜 2020-11-22 11:45

What is the difference between Task.WaitAll() and Task.WhenAll() from the Async CTP ? Can you provide some sample code to illustrate the different

4条回答
  •  轮回少年
    2020-11-22 12:42

    Task.WaitAll blocks the current thread until everything has completed.

    Task.WhenAll returns a task which represents the action of waiting until everything has completed.

    That means that from an async method, you can use:

    await Task.WhenAll(tasks);
    

    ... which means your method will continue when everything's completed, but you won't tie up a thread to just hang around until that time.

提交回复
热议问题