如何获得第二个 System.Thread.ThreadPool?

时间:2023-02-17
本文介绍了如何获得第二个 System.Thread.ThreadPool?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我以嵌套方式使用 ThreadPool,我的应用程序就会挂起:

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

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

如何获得第二个独立的ThreadPool来实现嵌套?

How to get a second and independent ThreadPool to achieve nesting?

推荐答案

只有一个 ThreadPool - 您不能(或应该)在一个应用程序中创建多个实例.

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

我不建议这样做,但如果您真的想这样做,您可以使用自己的 ThreadPool 实现的多个实例,例如 SmartThreadPool.从技术上讲,这将允许单独的线程池".

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".

但是,我怀疑您因为 死锁 而挂起,而不是因为线程池用法.我会调查你在哪里遇到问题.如果您安装了 VS 2010 测试版的副本,则 VS2010 并发可视化工具对此非常有用.

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.

这篇关于如何获得第二个 System.Thread.ThreadPool?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:.NET - 用单个 using 语句替换嵌套 using 语句 下一篇:在 ASP.NET Web 应用程序中创建嵌套母版页

相关文章

最新文章