Parallel.For和Parallel.Foreach中长时间运行的任务 [英] Long running Task in Parallel.For and Parallel.Foreach

查看:222
本文介绍了Parallel.For和Parallel.Foreach中长时间运行的任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何在Parallel.ForEach中设置TaskCreationOptions.LongRunning?



我有与远程系统通信的可变任务量(0 - 50)。


如果任务在线程池上运行,则会导致某种计时器饥饿(延迟执行)计时器)。


解决方案是增加线程池的最小线程数或者自己创建任务。


但最优雅的是指定TaskCreationOptions


解决方案


我担心使用"Parallel.ForEach"这是不可能的......您只能在"Task.Factory.StartNew"中指定此选项。方法。


关于这一点,也许这可能让你感兴趣:

http://stackoverflow.com/questions/10687850/task-factory-startnew-or-parallel-foreach-for-many-long-运行的任务


How is can i set the TaskCreationOptions.LongRunning in Parallel.ForEach?

I have variable amount of task (0 - 50) that communicate with a remote system.

If the tasks run on the threadpool this leads to some kind of timer starvation (deferred execution of timer).

Solutions are to increase min thread count of the threadpool or to create the tasks on myself.

But most elegant would be to specify TaskCreationOptions

解决方案

Hi,

I'm afraid that with the "Parallel.ForEach" it is not possible... You can only specify this option in the "Task.Factory.StartNew" method.

About this, maybe this could interest you :
http://stackoverflow.com/questions/10687850/task-factory-startnew-or-parallel-foreach-for-many-long-running-tasks


这篇关于Parallel.For和Parallel.Foreach中长时间运行的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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