ThreadPool.GetMinThreads(Int32, Int32) Metodo

Definizione

Recupera il numero minimo di thread creati dal pool di thread su richiesta, man mano che vengono effettuate nuove richieste, prima di passare a un algoritmo per la gestione della creazione e della distruzione del thread.

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

Quando termina, questo metodo contiene il numero minimo di thread di lavoro creati dal pool di thread su richiesta.

completionPortThreads
Int32

Quando termina, questo metodo contiene il numero minimo di thread di I/O asincroni creati dal pool di thread su richiesta.

Esempio

L'esempio seguente imposta il numero minimo di thread di lavoro su quattro e mantiene il valore originale per il numero minimo di thread di completamento di I/O asincroni.

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 finché non raggiunge il valore minimo per ogni categoria. Per impostazione predefinita, il numero minimo di thread corrisponde al numero di processori in un sistema. Quando viene raggiunto il valore minimo, il pool di thread può creare thread aggiuntivi in tale categoria o attendere il completamento di alcune attività. A partire da .NET Framework 4, il pool di thread crea ed elimina i thread per ottimizzare la velocità effettiva, definita come numero di attività completate per unità di tempo. Un numero eccessivo di thread potrebbe non usare in modo ottimale le risorse disponibili, mentre un numero eccessivo di thread potrebbe aumentare la contesa delle risorse.

Note

Quando la domanda è bassa, il numero effettivo di thread del pool può scendere sotto i valori minimi.

Si applica a

Vedi anche