ThreadPool.GetMinThreads(Int32, Int32) メソッド

定義

スレッドの作成と破棄を管理するためのアルゴリズムに切り替える前に、新しい要求が行われると、スレッド プールが必要に応じて作成するスレッドの最小数を取得します。

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)

パラメーター

workerThreads
Int32

このメソッドから制御が戻るときに、スレッド プールがオンデマンドで作成するワーカー スレッドの最小数を格納します。

completionPortThreads
Int32

このメソッドから制御が戻るときに、スレッド プールがオンデマンドで作成する非同期 I/O スレッドの最小数が格納されます。

次の例では、ワーカー スレッドの最小数を 4 に設定し、非同期 I/O 完了スレッドの最小数の元の値を保持します。

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

注釈

スレッド プールは、各カテゴリの最小値に達するまで、新しいワーカー スレッドまたは I/O 完了スレッドをオンデマンドで提供します。 既定では、スレッドの最小数はシステム上のプロセッサの数に設定されます。 最小値に達すると、スレッド プールはそのカテゴリに追加のスレッドを作成するか、一部のタスクが完了するまで待機できます。 .NET Framework 4 以降では、スレッド プールはスループットを最適化するためにスレッドを作成および破棄します。これは、時間単位で完了したタスクの数として定義されます。 使用可能なリソースを最適に使用できないスレッドが少なすぎるのに対し、スレッドの数が多すぎるとリソースの競合が増加する可能性があります。

Note

需要が低い場合、スレッド プール スレッドの実際の数が最小値を下回る可能性があります。

適用対象

こちらもご覧ください