WaitAll vs WhenAll [英] WaitAll vs WhenAll

查看:33
本文介绍了WaitAll vs WhenAll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Async CTP 中的 Task.WaitAll()Task.WhenAll() 有什么区别?您能否提供一些示例代码来说明不同的用例?

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

推荐答案

Task.WaitAll 阻塞当前线程,直到一切都完成.

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

Task.WhenAll 返回一个 task 表示等待一切完成的动作.

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.

这篇关于WaitAll vs WhenAll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆