Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Método ThreadPool::SetMinThreads (Int32, Int32)

 

Establece el número mínimo de subprocesos que el grupo de subprocesos crea a petición, según se realizan nuevas solicitudes, antes de conmutar a un algoritmo para administrar la creación y destrucción de subprocesos.

Espacio de nombres:   System.Threading
Ensamblado:  mscorlib (en mscorlib.dll)

public:
[SecurityPermissionAttribute(SecurityAction::Demand, ControlThread = true)]
static bool SetMinThreads(
	int workerThreads,
	int completionPortThreads
)

Parámetros

workerThreads
Type: System::Int32

Número mínimo de subprocesos de trabajo que el grupo de subprocesos crea a petición.

completionPortThreads
Type: System::Int32

Número mínimo de subprocesos de E/S asincrónicos que el grupo de subprocesos crea a petición.

Valor devuelto

Type: System::Boolean

Es true si el cambio se realiza correctamente; en caso contrario, es false.

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 M:System.Threading.ThreadPool.GetMaxThreads(System.Int32@,System.Int32@)), M:System.Threading.ThreadPool.SetMinThreads(System.Int32,System.Int32) returns false and does not change either of the minimum values.

System_CAPS_cautionPrecaución

By default, the minimum number of threads is set to the number of processors on a system. You can use the M:System.Threading.ThreadPool.SetMinThreads(System.Int32,System.Int32) method to increase the minimum number ofthreads. 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.

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

SecurityPermission

for the ability to control threads. Permission value: F:System.Security.Permissions.SecurityPermissionFlag.ControlThread

.NET Framework
Disponible desde 1.1
Silverlight
Disponible desde 2.0
Windows Phone Silverlight
Disponible desde 7.0
Volver al principio
Mostrar: