TPL - 我怎么能强迫TPL使用线程固定#?不低于 [英] TPL - How can I force TPL to use fixed # of threads? not less
问题描述
我怎么能强迫TPL使用固定线程数?我知道MaxDegreeOfParallelism可以用来设置上限,但我想要的上限为等于下限。这可能吗?怎么样?
How can I force TPL to use a fixed number of threads? I know MaxDegreeOfParallelism can be used to set the upper limit, but I want the upper limit to equal the lower limit. Is this possible? How?
由于我知道有人会问=)是的,我敢肯定,我要做到这一点,它是最适合我的scneario。 =)
Because I know someone will ask =) yes, I'm sure I want to do this and yes its optimal for my scneario. =)
修改
该解决方案需要自定义分区程序以及自定义的TaskScheduler <一href="http://social.msdn.microsoft.com/Forums/en-US/parallelextensions/thread/002ff888-6e13-4d7e-a234-1632e8a1f551" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/parallelextensions/thread/002ff888-6e13-4d7e-a234-1632e8a1f551
EDIT
The solution requires a custom Partitioner as well as the custom TaskScheduler http://social.msdn.microsoft.com/Forums/en-US/parallelextensions/thread/002ff888-6e13-4d7e-a234-1632e8a1f551
推荐答案
您可以创建自己的<一href="http://msdn.microsoft.com/en-us/library/system.threading.tasks.taskscheduler.aspx">TaskScheduler如果你真的需要,但使用TaskCreationOptions.LongRunning可能是最好的办法。
You could create your own TaskScheduler if you really needed to, but using TaskCreationOptions.LongRunning is probably the best approach.
这篇关于TPL - 我怎么能强迫TPL使用线程固定#?不低于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!