Tuesday 24 June 2014

ThreadPool

A friend of mine a few years back was asked in an interview how many threads are in the .NET threadpool by default.

He asked me after the interview and I had no idea.  So we did some research and it turns out not many people on the internet knew either. 

Turns out it depends the version of the .NET Framework, how many cores, 32/64 bit.

Here’s some code to find out on your machine and .NET framework setup:

class Program
{
static void Main(string[] args)
{
int workerThreads, completionPortThreads;

ThreadPool.GetMinThreads(out workerThreads, out completionPortThreads);
Console.WriteLine("Min worker threads {0}, completionPortThreads {1}", workerThreads, completionPortThreads);

ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads);
Console.WriteLine("Max worker threads {0}, completionPortThreads {1}", workerThreads, completionPortThreads);

ThreadPool.GetAvailableThreads(out workerThreads, out completionPortThreads);
Console.WriteLine("Available worker threads {0}, completionPortThreads {1}", workerThreads, completionPortThreads);

Console.ReadKey();
}
}

image

No comments:

Post a Comment