如何获得第二个 System.Thread.ThreadPool?
- 作者: 湾仔大宇哥
- 来源: 51数据库
- 2022-10-28
问题描述
如果我以嵌套方式使用 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.
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
