TPL - 我怎么能强迫TPL使用线程固定#?不低于线程、不低于、我怎么能、TPL

由网友(人荡无罪 物荡必碎)分享简介:我怎么能强迫TPL使用固定线程数?我知道MaxDegreeOfParallelism可以用来设置上限,但我想要的上限为等于下限。这可能吗?怎么样?How can I force TPL to use a fixed number of threads? I know MaxDegreeOfParallelism c...

我怎么能强迫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 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

推荐答案

您可以创建自己的TaskScheduler如果你真的需要,但使用TaskCreationOptions.LongRunning可能是最好的办法。

You could create your own TaskScheduler if you really needed to, but using TaskCreationOptions.LongRunning is probably the best approach.

如何创建一个任务计划,限制并发度

阅读全文

相关推荐

最新文章