How to get a second System.Thread.ThreadPool?(如何获得第二个 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获得第二个 System.Thread.ThreadPool?
- 在 C# 中异步处理项目队列 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- 使用 rss + c# 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01