相关疑难解决方法(0)

ThreadPool最大线程数

我在使用.NET的ThreadPool(.NET 4)时遇到了一些麻烦.

我已经读过默认情况下.NET每个处理器有25个线程的限制,但根据SO和其他地方的论坛帖子,我可以使用下面的代码增加限制.

void SetThreads(int threads)
{
    ThreadPool.SetMaxThreads(threads, threads);
    ThreadPool.SetMinThreads(threads, threads);
}
Run Code Online (Sandbox Code Playgroud)

但是,当我将上面的内容设置为某个任意高的数字(例如2000)和队列~1000个项目时,我仍然只有~33个线程在运行(.NET CLR需要约5个线程),并ThreadPool.GetAvailableThreads()返回剩余的1971个线程.

为什么上面的代码不起作用?

.net c# multithreading threadpool

25
推荐指数
2
解决办法
5万
查看次数

标签 统计

.net ×1

c# ×1

multithreading ×1

threadpool ×1