在 Windows 工作流基础 4.0 中限制并行 foreach 的线程数 [英] Restrict number of threads in parallel foreach in Windows workflow foundation 4.0

查看:34
本文介绍了在 Windows 工作流基础 4.0 中限制并行 foreach 的线程数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 WF,其中我使用并行 foreach 来枚举项目列表并对每个项目进行一些处理.要求是无限地运行并行 foreach,直到用户干预并停止该过程.然而,当项目超过 20 项时,我看到多个线程被分拆,CPU 使用率将飙升至 99%,最终整个系统的响应速度变慢.如何限制可以为每个 WWF 并行创建的线程数.有什么我可以设置的属性吗?任何帮助都受到高度赞赏.

I have WF in which I am using parallel foreach to enumerate through a list of items and do some Processing on each item. The requirement is to run the parallel foreach infinitely until the user intervenes and stops the process. However when there are more than 20 items, I see multiple threads are spun off and the CPU usage will spike to 99 percentages and eventually the entire system slows down to respond. How can I limit the number of threads that can be created in parallel foreach of WWF. Is there any property that I can set? Any help is highly appreciated.

推荐答案

WF4 不会为项目创建新线程.只有当使用异步活动时,您才会获得任何重叠的活动执行.通常这对异步 IO 效果最好,但如果您通过启动其他线程在您的活动中这样做,您可以进行后台编译.尽管 WF 运行时每个工作流实例仅使用一个线程.

WF4 doesn't create new threads for the items. Only when async activities are used will you get any overlapping execution of activities. Normally this works best with asynchronous IO but you can do background compilation if you do so in your activity by starting other threads. The WF runtime will only use a single thread per workflow instance though.

这篇关于在 Windows 工作流基础 4.0 中限制并行 foreach 的线程数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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