为WaitAll VS WhenAll [英] WaitAll vs WhenAll

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

问题描述

什么是 Task.WaitAll之间的差值() TaskEx.WhenAll()从异步CTP?
你能提供一些示例code来说明不同的使用情况?

What is the difference between Task.WaitAll() and TaskEx.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.

TaskEx.WhenAll 返回任务的其中重presents等待,直到一切都已经完成了行动。

TaskEx.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 TaskEx.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天全站免登陆