How to get a second System.Thread.ThreadPool?

前端 未结 6 1832
自闭症患者
自闭症患者 2021-01-18 23:16

If I use the ThreadPool in a nested way, my application hangs:

 ThreadPool.QueueUserWorkItem((state) =>
      ThreadPool.QueueUserWorkItem(Action));
         


        
6条回答
  •  爱一瞬间的悲伤
    2021-01-18 23:55

    There is only one single ThreadPool - it's not something you can (or should) make more than one instance of in an application.

    I don't recommend doing this, but if you really wanted to, you could use multiple instances of your own ThreadPool implementation, such as SmartThreadPool. This would, technically, allow separate "thread pools".

    However, I suspect you're hanging due to a deadlock, not due to the ThreadPool usage. I would investigate where you're getting the hangs. The VS2010 concurrency visualizer is very nice for this, if you have a copy of the VS 2010 beta installed.

提交回复
热议问题