.Net How to create a custom ThreadPool shared across all the AppDomain of a process?

前端 未结 2 530
天命终不由人
天命终不由人 2021-02-10 15:38

I made a custom ThreadPool optimized for my specific needs. However, when there are multiple AppDomains in the process, the CLR ThreadPool is able to be shared across all the Ap

相关标签:
2条回答
  • 2021-02-10 16:12

    Create a new threadpool instance in each appdomain, but then use a semaphore to control the total number of threads running across all instances. This means you can still get the same total concurrent jobs processed, but don't have the grief of marshalling.

    The MSDN docs have an example.

    0 讨论(0)
  • 2021-02-10 16:34

    After thinking more about it, it's probably a bad idea to try to reimplement a process wide ThreadPool, the CLR ThreadPool is already optimized for this.

    For my case, I wanted more flexibility to be able to prioritize work items queued into the pool, this can be done with a layer built on top of the existing CLR ThreadPool.

    0 讨论(0)
提交回复
热议问题