Idle threads are maintained by the thread pool in order to reduce the time required to satisfy requests for thread pool threads. Separate minimums are maintained for worker threads and asynchronous I/O threads. Idle threads in excess of the minimums are terminated, to save system resources. Maintenance of the idle threads is a background task.
Note: |
|---|
GetMinThreads and SetMinThreads retrieve and set the total number of idle threads maintained by the thread pool, regardless of the number of processors in the computer.
|
If you specify a negative number or a number larger than the maximum number of active thread pool threads (obtained using GetMaxThreads), SetMinThreads returns false and does not change either of the minimum values.
Caution: |
|---|
Reducing the number of idle threads to less than the number of processors can hurt performance
.
|
When all thread pool threads have been assigned to tasks, the thread pool does not immediately begin creating new idle threads. To avoid unnecessarily allocating stack space for threads, it creates new idle threads at intervals. The interval is currently half a second, although it could change in future versions of the .NET Framework.
If an application is subject to bursts of activity in which large numbers of thread pool tasks are queued, use the SetMinThreads method to increase the minimum number of idle threads. Otherwise, the built-in delay in creating new idle threads could cause a bottleneck. A small increase in the number of idle threads can produce a significant improvement in throughput.
Note: |
|---|
Unnecessarily increasing the number of idle threads can also cause performance problems. Stack space must be allocated for each thread. If too many tasks start at the same time, all of them might appear to be slow. Finding the right balance is a performance-tuning issue
.
|