Active thread pool topic number

When I write the code below, why do I get an available topic number, for example 1022, 1020. I use the thread pool to get 25 thread max.

I think the output stream number is the available threads in the system. I need to get an available thread number in my thread pool, in a win form application.

private void Foo() { int intAvailableThreads, intAvailableIoAsynThreds; // ask the number of avaialbe threads on the pool, //we really only care about the first parameter. ThreadPool.GetAvailableThreads(out intAvailableThreads, out intAvailableIoAsynThreds); // build a message to log string strMessage = String.Format(@"Is Thread Pool: {1}, Thread Id: {2} Free Threads {3}", Thread.CurrentThread.IsThreadPoolThread.ToString(), Thread.CurrentThread.GetHashCode(), intAvailableThreads); // check if the thread is on the thread pool. Trace.WriteLine(strMessage); // create a delay... Thread.Sleep(30000); return; } 

Thank you so much.

(Note: I got the code http://www.codeproject.com/KB/cs/AsyncMethodInvocation.aspx ) Good article!

+6
c # threadpool
source share
4 answers

I need to get 25 thread max since I am using thread pool.

The number of threads in the thread pool per core has changed a lot over time. This is no more than 25 per core, which I suspect you expect.

For example, running this on my quad-core hyperthreading laptop with .NET 4, I get 32767 workflows and 1000 I / O ports:

 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); } } 

In .NET 3.5, I get 2000 workflows and still 1000 I / O ports.

+8
source share

Use ThreadPool.GetMaxThreads to get what you want.

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

+4
source share

I set both values ​​to 10001 using ThreadPool.SetMaxThread. After that, whenever I run your program, it shows a maximum stream of 10001, it is saved. I did not restart my base system I am 5.

After that I set both values ​​to 10000000 and it displays the next maximum number of threads

work: 32767 ioCompletion: 32767

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

+1
source share
 int available; int maxLimit; System.Threading.ThreadPool.GetAvailableThreads(out available, out maxLimit); 
-one
source share

All Articles