Export (0) Print
Expand All

ThreadPool.GetMinThreads Method

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Retrieves the number of idle threads the ThreadPool maintains in anticipation of new requests.

[Visual Basic]
Public Shared Sub GetMinThreads( _
   <Out()> ByRef workerThreads As Integer, _
   <Out()> ByRef completionPortThreads As Integer _
)
[C#]
public static void GetMinThreads(
   out int workerThreads,
   out int completionPortThreads
);
[C++]
public: static void GetMinThreads(
   [
   Out
] int* workerThreads,
   [
   Out
] int* completionPortThreads
);
[JScript]
public static function GetMinThreads(
   workerThreads : int,
 completionPortThreads : int
);

Parameters

workerThreads
The minimum number of idle worker threads currently maintained by the thread pool.
completionPortThreads
The minimum number of idle asynchronous I/O threads currently maintained by the thread pool.

Remarks

Idle threads are maintained by the thread pool in order to reduce the time required to satisfy requests for thread pool threads. Idle threads in excess of the minimums are terminated, to save system resources. Maintenance of the idle threads is a background task.

When GetMinThreads returns, the variable specified by workerThreads contains the minimum number of idle worker threads the thread pool maintains, and the variable specified by completionPortThreads contains the minimum number of idle asynchronous I/O threads the thread pool maintains.

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.

Example

[Visual Basic, C#, C++] The following example sets the minimum number of idle worker threads to four (4), and preserves the original value for the minimum number of idle IO completion threads.

[Visual Basic] 
Imports System
Imports System.Threading

Public Class Test
    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

[C#] 
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.
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Threading;

int main()
{
    int minWorker, 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.
    }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ThreadPool Class | ThreadPool Members | System.Threading Namespace | SetMinThreads | GetMaxThreads | GetAvailableThreads

Show:
© 2014 Microsoft