Workflow 4.0 中的多线程
我希望 foreach
I want each sequence inside a foreach<T>
activity running in a different thread. Is this possible by using WWF 4.0? If not, how can I achieve multithreading in WWF 4.0?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于您正在从事的工作类型。默认情况下,工作流调度程序此时只会执行工作流中的单个活动,没有办法解决这个问题。并行活动同时安排多个子活动,但它们不并行执行。
该规则的一个大例外是 AsyncCodeActivity 类型的活动。一旦调度程序执行一些异步操作,就会执行另一个活动。现在,这最适合 IO 绑定工作,例如数据库访问或网络 IO,但这不是必需的。
因此,为了在工作流程中实现真正的并行性,您需要将并行活动之一与从 AsyncCodeActivity 派生的活动结合使用。
It depends on the kind of work you are doing. By default the workflow scheduler will only execute a single activity in a workflow at the time, no way around that. The parallel activities schedule multiple child activities at the same time but they don't execute in parallel.
The big exception to the rule is AsyncCodeActivity type activities. The scheduler will execute another activity as soon as they are doing some asynchronous stuff. Now this works best with IO bound work like database access or network IO but that is not a requirement.
So to achieve true parallelism in your workflows you need to be use a combination of one of the parallel activities with activities deriving from AsyncCodeActivity.
要实现 foreach 的并行执行,请使用 ParallelForEach。
To achieve parallel execution of a foreach, use ParallelForEach.