线程池的最大线程 [英] ThreadPool max threads

查看:227
本文介绍了线程池的最大线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有了与.NET的线程池(.NET 4)一些麻烦。

I've got some trouble with .NET's ThreadPool (.NET 4).

我读过,在默认情况下.NET具有每处理器25个线程的限制,但根据对SO和其他地方,我可以用低于code提高限额。

I've read that by default .NET has a limit of 25 threads per processor, but according to forum posts on SO and on other places, I can increase the limit with the below code.

void SetThreads(int threads)
{
    ThreadPool.SetMaxThreads(threads, threads);
    ThreadPool.SetMinThreads(threads, threads);
}

然而,当我把上面的一些任意高的数字,例如,2000年,和队列〜1000个项目,我仍然只有运行〜33线程(.NET CLR大约需要5个线程),而 ThreadPool.GetAvailableThreads()返回剩余的1971年主题。

However, when I set the above to some arbitrarily high number, for example, 2000, and queue ~1000 items, I still only have ~33 threads running (.NET CLR takes ~5 threads), and ThreadPool.GetAvailableThreads() returns 1971 threads remaining.

为什么没有code以上的工作?

Why doesn't the code above work?

推荐答案

从在MSDN :当需求不足时,线程池中的线程的实际数量可低于最低值

From the MSDN : When demand is low, the actual number of thread pool threads can fall below the minimum values.

了解这一点:<一href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=86b3d32b-ad26-4bb8-a3ae-c1637026c3ee&displaylang=en">Patterns并行编程:了解和应用并行模式与.NET Framework 4

这篇关于线程池的最大线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆