Search code examples
c#.netdefaultthreadpool

Default values for System.Threading.ThreadPool.SetMaxThreads


Suppose, I don't set any values explicitly by calling the function:

System.Threading.ThreadPool.SetMaxThreads

What are the default values?


Solution

  • It depends on the .NET framework version, changed in 2.0, 3.0 and 4.0. In 2.0 it was 50 times the number of cores. In 3.0 (aka 2.0 SP1) it was 250 times the number of cores, 4.0 made it dynamic depending on bitness and OS resources. Max I/O completion threads was always 1000 if I remember correctly.

    In general, it is insanely high and a program should never get close. On a 32-bit machine, the program is pretty likely to bomb with OOM first when all of those threads consume the available virtual memory with their one megabyte stacks. In general, it can only get out of hand when there are a lot of TP thread requests and the running ones are not completing for minutes. The ideal for a TP thread is to not take more than half a second.

    The Debug > Windows > Threads debugger window tells the unpleasant truth. And gives a very good hint why these TP threads are not completing, you can see their call stack.