Active Thread Number in Thread Pool

旧巷老猫 提交于 2019-11-30 07:25:22

I have to get 25 thread max as I am using thread pool.

The maximum number of threads in the thread-pool per core has changed a lot over time. It's no longer 25 per core, which I suspect is what you were expecting.

For example, running this on my quad-core hyperthreaded laptop with .NET 4, I get a maximum of 32767 worker threads and 1000 IO completion port threads:

using System;
using System.Threading;

class Test
{
    static void Main()
    {
        int worker; 
        int ioCompletion;
        ThreadPool.GetMaxThreads(out worker, out ioCompletion);
        Console.WriteLine("{0} / {1}", worker, ioCompletion);
    }    
}

Under .NET 3.5 I get 2000 worker threads and still 1000 IO completion port threads.

That isn't the number of threads actually in the thread pool though - it's the maximum number that the thread pool allows itself to create over time.

John Arlen

Use ThreadPool.GetMaxThreads to get what you want.

This article helps explain everything you need to know about ThreadPool.

I set both to 10001, using ThreadPool.SetMaxThread. After that whenever, I run your program it shows max thread 10001, its persisted. I didn't restarted my core i 5 system.

After that I set both it to 10000000 , and it is showing following thread max count

worker:32767 ioCompletion:32767

So on my Windows 7 Intel Core i5 , this is the maximum capacity.

developer747
int available;
int maxLimit;
System.Threading.ThreadPool.GetAvailableThreads(out available, out maxLimit);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!