Skip to main content
.NET Framework Class Library
ThreadPool..::.GetMinThreads Method

Updated: October 2010

Retrieves 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.

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Syntax
Public Shared Sub GetMinThreads ( _
	<OutAttribute> ByRef workerThreads As Integer, _
	<OutAttribute> ByRef completionPortThreads As Integer _
)
public static void GetMinThreads(
	out int workerThreads,
	out int completionPortThreads
)
public:
static void GetMinThreads(
	[OutAttribute] int% workerThreads, 
	[OutAttribute] int% completionPortThreads
)
static member GetMinThreads : 
        workerThreads:int byref * 
        completionPortThreads:int byref -> unit 

Parameters

workerThreads
Type: System..::.Int32%
When this method returns, contains the minimum number of worker threads that the thread pool creates on demand.
completionPortThreads
Type: System..::.Int32%
When this method returns, contains the minimum number of asynchronous I/O threads that the thread pool creates on demand.
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 Framework 4, 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.

NoteNote

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

Examples

The following example sets the minimum number of worker threads to four, and preserves the original value for the minimum number of asynchronous I/O completion threads.


Imports System
Imports System.Threading

Public Class Test

    <MTAThread> _
    Public Shared Sub Main()
        Dim minWorker, minIOC As Integer
        ' Get the current settings.
        ThreadPool.GetMinThreads(minWorker, minIOC)
        ' Change the minimum number of worker threads to four, but
        ' keep the old setting for minimum asynchronous I/O 
        ' completion threads.
        If ThreadPool.SetMinThreads(4, minIOC) Then
            ' The minimum number of threads was set successfully.
        Else
            ' The minimum number of threads was not changed.
        End If
    End Sub
End Class


using System;
using System.Threading;

public class Test
{
    public static void Main()
    {
        int minWorker, minIOC;
        // Get the current settings.
        ThreadPool.GetMinThreads(out minWorker, out minIOC);
        // Change the minimum number of worker threads to four, but
        // keep the old setting for minimum asynchronous I/O 
        // completion threads.
        if (ThreadPool.SetMinThreads(4, minIOC))
        {
            // The minimum number of threads was set successfully.
        }
        else
        {
            // The minimum number of threads was not changed.
        }
    }
}


using namespace System;
using namespace System::Threading;
int main()
{
   int minWorker;
   int minIOC;

   // Get the current settings.
   ThreadPool::GetMinThreads( minWorker, minIOC );

   // Change the minimum number of worker threads to four, but
   // keep the old setting for minimum asynchronous I/O
   // completion threads.
   if ( ThreadPool::SetMinThreads( 4, minIOC ) )
   {

      // The minimum number of threads was set successfully.
   }
   else
   {

      // The minimum number of threads was not changed.
   }
}


Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Change History

Date

History

Reason

October 2010

Updated to more accurately describe .NET Framework 4 behavior.

Content bug fix.