Suppose, I don't set any values explicitly by calling the function:
System.Threading.ThreadPool.SetMaxThreads
What are the default values?
The size for the default thread pool is set to 10 minimum and 10 maximum threads. A timeout value is set to 3500 milliseconds.
Thread pool in C# is a collection of threads. It is used to perform tasks in the background. When a thread completes a task, it is sent to the queue wherein all the waiting threads are present. This is done so that it can be reused.
QueueUserWorkItem(WaitCallback, Object) Queues a method for execution, and specifies an object containing data to be used by the method. The method executes when a thread pool thread becomes available.
To set the lower limit of the threads in the thread pool you can use the ThreadPool. SetMinThreads property. The default lower limit of the number of threads in the thread pool is one thread per processor.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With