ThreadPool.GetMinThreads(Int32, Int32) ThreadPool.GetMinThreads(Int32, Int32) ThreadPool.GetMinThreads(Int32, Int32) ThreadPool.GetMinThreads(Int32, Int32) Method

Definizione

Recupera il numero minimo di thread che il pool di thread crea, man mano che vengono effettuate nuove richieste, prima di passare a un algoritmo per la gestione della creazione e dell'eliminazione del thread.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.

public:
 static void GetMinThreads([Runtime::InteropServices::Out] int % workerThreads, [Runtime::InteropServices::Out] int % completionPortThreads);
public static void GetMinThreads (out int workerThreads, out int completionPortThreads);
static member GetMinThreads : int * int -> unit
Public Shared Sub GetMinThreads (ByRef workerThreads As Integer, ByRef completionPortThreads As Integer)

Parametri

workerThreads
Int32 Int32 Int32 Int32

Quando il metodo viene restituito, contiene il numero minimo di thread di lavoro che il pool di thread crea su richiesta.When this method returns, contains the minimum number of worker threads that the thread pool creates on demand.

completionPortThreads
Int32 Int32 Int32 Int32

Quando il metodo viene restituito, contiene il numero minimo di thread I/O asincroni che il pool di thread crea su richiesta.When this method returns, contains the minimum number of asynchronous I/O threads that the thread pool creates on demand.

Esempi

Nell'esempio seguente viene impostato il numero minimo di thread di lavoro su quattro e viene mantenuto il valore originale per il numero minimo di thread di completamento di I/O asincroni.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.
   }
}

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

Commenti

Il pool di thread fornisce nuovi thread di lavoro o thread di completamento di I/O su richiesta fino a raggiungere il valore minimo per ogni categoria.The thread pool provides new worker threads or I/O completion threads on demand until it reaches the minimum for each category. Per impostazione predefinita, il numero minimo di thread è impostato sul numero di processori in un sistema.By default, the minimum number of threads is set to the number of processors on a system. Quando viene raggiunto il valore minimo, il pool di thread può creare thread aggiuntivi in tale categoria o attendere il completamento di alcune attività.When the minimum is reached, the thread pool can create additional threads in that category or wait until some tasks complete. A partire da .NET Framework 4.NET Framework 4, il pool di thread crea ed Elimina i thread per ottimizzare la velocità effettiva, definita come il numero di attività completate per unità di tempo.Beginning with the .NET Framework 4.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. Un numero troppo ridotto di thread potrebbe non usare in modo ottimale le risorse disponibili, mentre troppi thread potrebbero aumentare il conflitto per le risorse.Too few threads might not make optimal use of available resources, whereas too many threads could increase resource contention.

Nota

Quando la richiesta è bassa, il numero effettivo di thread del pool può scendere sotto i valori minimi.When demand is low, the actual number of thread pool threads can fall below the minimum values.

Si applica a

Vedi anche