次の方法で共有


ThreadPool.GetMinThreads メソッド

メモ : この名前空間、クラス、およびメンバは、.NET Framework Version 1.1 だけでサポートされています。

新しい要求に応じるために ThreadPool 内で保持されている、アイドル状態のスレッドの数を取得します。

Public Shared Sub GetMinThreads( _
   <Out()> ByRef workerThreads As Integer, _   <Out()> ByRef completionPortThreads As Integer _)
[C#]
public static void GetMinThreads(   out intworkerThreads,   out intcompletionPortThreads);
[C++]
public: static void GetMinThreads(   [   Out] int* workerThreads,   [   Out] int* completionPortThreads);
[JScript]
public static function GetMinThreads(
   workerThreads : int,completionPortThreads : int);

パラメータ

  • workerThreads
    スレッド プール内に現在保持されているアイドル状態のワーカー スレッドの最小数。
  • completionPortThreads
    スレッド プール内に現在保持されているアイドル状態の非同期 I/O スレッドの最小数。

解説

スレッド プール内にアイドル状態のスレッドを保持するのは、スレッド プールのスレッドが要求された場合に、要求にすばやく応じるためです。アイドル状態のスレッドが最小数を超えると、システム リソースを節約するために余分なスレッドが終了されます。アイドル状態のスレッドの保持はバックグラウンド タスクが担当します。

GetMinThreads を呼び出すと、 workerThreads に指定した変数には、スレッド プールに保持されているアイドル状態のワーカー スレッドの最小数が格納され、 completionPortThreads に指定した変数には、スレッド プールに保持されているアイドル状態の非同期 I/O スレッドの最小数が格納されます。

メモ    GetMinThreadsSetMinThreads は、コンピュータのプロセッサ数に関係なしに、スレッド プールに保持されるアイドル状態のスレッドの総数を取得および設定します。

使用例

[Visual Basic, C#, C++] アイドル状態のワーカー スレッド数を 4 に設定し、アイドル状態の IO 完了スレッドの最小値については元の値を保持する例を次に示します。

 
Imports System
Imports System.Threading

Public Class Test
    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

[C#] 
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.
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Threading;

int main()
{
    int minWorker, 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.
    }
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

ThreadPool クラス | ThreadPool メンバ | System.Threading 名前空間 | SetMinThreads | GetMaxThreads | GetAvailableThreads