我怎样才能等到Parallel.ForEach完成 [英] How can I wait till the Parallel.ForEach completes

查看:3009
本文介绍了我怎样才能等到Parallel.ForEach完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我目前的项目中使用TPL和使用Parallel.Foreach旋转多个线程。任务类包含等待()等到任务完成得到。这样,我怎么能等待Parallel.ForEach完成,然后进入下一个执行的语句?

I'm using TPL in my current project and using Parallel.Foreach to spin many threads. The Task class contains Wait() to wait till the task gets completed. Like that, how I can wait for the Parallel.ForEach to complete and then go into executing next statements?

推荐答案

您别吨有做什么特别, Parallel.Foreach()将等到所有分支任务完成。从调用线程,你可以把它当作一个同步的声明,比如把它包装在try / catch里面。

You don't have to do anything special, Parallel.Foreach() will wait until all its branched tasks are complete. From the calling thread you can treat it as a single synchronous statement and for instance wrap it inside a try/catch.

这篇关于我怎样才能等到Parallel.ForEach完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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