System.Threading.ThreadPool.SetMinThreads Method

Sets the minimum number of threads the thread pool creates on demand, as new requests are made, before switching to an algorithm for managing thread creation and destruction.

Syntax

public static bool SetMinThreads (int workerThreads, int completionPortThreads)

Parameters

workerThreads
The minimum number of worker threads that the thread pool creates on demand.
completionPortThreads
The minimum number of asynchronous I/O threads that the thread pool creates on demand.

Returns

true if the change is successful; otherwise, false.

Remarks

The thread pool provides new worker threads or I/O completion threads on demand until it reaches the minimum for each category. When the minimum is reached, the thread pool can create additional threads in that category or wait until some tasks complete. Beginning with the net_v40_short, the thread pool creates and destroys threads in order to optimize throughput, which is defined as the number of tasks that complete per unit of time. Too few threads might not make optimal use of available resources, whereas too many threads could increase resource contention.

When demand is low, the actual number of thread pool threads can fall below the minimum values.

If you specify a negative number or a number larger than the maximum number of active thread pool threads (obtained using ThreadPool.GetMaxThreads(Int32@, Int32@)), ThreadPool.SetMinThreads(int, int) returns false and does not change either of the minimum values.

Note:

You can use the ThreadPool.SetMinThreads(int, int) method to increase the minimum number of threads. However, unnecessarily increasing these values can cause performance problems. If too many tasks start at the same time, all of them might appear to be slow. In most cases, the thread pool will perform better with its own algorithm for allocating threads. Reducing the minimum to less than the number of processors can also hurt performance.

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0