c# - 线程池中可用线程数

标签 c# .net multithreading threadpool threadpoolexecutor

在线程池中,我设置了最大线程数。我想要可用的工作线程数。我试过了。

     ThreadPool.GetAvailableThreads(out x, out y);

使用此方法,我得到的可用线程数 (x) 仅在减少。即使在任务完成后,可用线程数 (x) 也没有增加。 如何获取线程池中实际可用线程数。

最佳答案

GetAvailableThreads() 方法不会告诉您有多少个线程,它返回仍然可以创建多少个额外线程。

来自 MSDN:

When GetAvailableThreads returns, the variable specified by workerThreads contains the number of additional worker threads that can be started,

关于

here was no increase in a number of available threads (x) even after their task was done.

你等了多久?该池只会慢慢销毁空闲线程。

关于c# - 线程池中可用线程数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29898028/

相关文章:

c# - Dapper 抛出 "Invalid type owner for DynamicMethod."

c# - int.Parse(), int.TryParse(), Convert.Int32() 哪个处理转换速度更快

c# - .NET 图像是全黑的吗?

c - 如何等待启动线程执行初始化代码

C# 锁定在锁定 block 中重新分配的对象

c# - NHibernate.Exceptions.GenericADOException 为什么?

c# - 用户操作后从用户控件返回值

c# - 需要 Linq 表达式从对象字典(包含列表)创建字符串列表

c# - Roslyn TypeDeclarationSyntax、MethodDeclarationSyntax、FieldDeclarationSyntax 具有公共(public)属性但没有公共(public)基类或接口(interface)

java - 如何在 Java 中重用一个线程?