TPL - How can I force TPL to use fixed # of threads? not less

后端 未结 2 2038
一整个雨季
一整个雨季 2021-01-06 04:21

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.

2条回答
  •  一向
    一向 (楼主)
    2021-01-06 04:39

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

    How to: Create a Task Scheduler That Limits the Degree of Concurrency

提交回复
热议问题