Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ThreadPool::GetMinThreads Method (Int32%, Int32%)

 

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)

public:
static void GetMinThreads(
	[OutAttribute] int% workerThreads,
	[OutAttribute] int% completionPortThreads
)

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.

The thread pool provides new worker threads or I/O completion threads on demand until it reaches the minimum for each category. By default, the minimum number of threads is set to the number of processors on a system. 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.

System_CAPS_noteNote

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

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.

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

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show:
© 2017 Microsoft