Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework. Sets the number of idle threads the ThreadPool maintains in anticipation of new requests.
[Visual Basic]
Public Shared Function SetMinThreads( _
ByVal workerThreads As Integer, _
ByVal completionPortThreads As Integer _
) As Boolean
[C#]
public static bool SetMinThreads(
int workerThreads,
int completionPortThreads
);
[C++]
public: static bool SetMinThreads(
int workerThreads,
int completionPortThreads
);
[JScript]
public static function SetMinThreads(
workerThreads : int,
completionPortThreads : int
) : Boolean;
Parameters
- workerThreads
- The new minimum number of idle worker threads to be maintained by the thread pool.
- completionPortThreads
- The new minimum number of idle asynchronous I/O threads to be 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.
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. Maintaining a large number of idle threads consumes system resources. You may need to tune the number to achieve the best overall performance. A small increase in the number of idle threads can produce a significant improvement in throughput in applications that have periods of inactivity followed by bursts of heavy activity.
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
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 | GetMinThreads | GetMaxThreads | GetAvailableThreads