メモ : この名前空間、クラス、およびメンバは、.NET Framework Version 1.1 だけでサポートされています。
ThreadPool 内で新しい要求に応じるために保持されるアイドル状態のスレッド数を設定します。
Public Shared Function SetMinThreads( _
ByVal workerThreads As Integer, _ ByVal completionPortThreads As Integer _) As Boolean
[C#]
public static bool SetMinThreads(intworkerThreads,intcompletionPortThreads);
[C++]
public: static bool SetMinThreads(intworkerThreads,intcompletionPortThreads);
[JScript]
public static function SetMinThreads(
workerThreads : int,completionPortThreads : int) : Boolean;
パラメータ
- workerThreads
スレッド プール内に保持するアイドル状態のワーカー スレッドの新しい最小数。 - completionPortThreads
スレッド プール内に保持するアイドル状態の非同期 I/O スレッドの新しい最小数。
解説
スレッド プール内にアイドル状態のスレッドを保持するのは、スレッド プールのスレッドが要求された場合に、要求にすばやく応じるためです。アイドル状態のスレッドが最小数を超えると、システム リソースを節約するために余分なスレッドが終了されます。アイドル状態のスレッドの保持はバックグラウンド タスクが担当します。
メモ GetMinThreads と SetMinThreads は、コンピュータのプロセッサ数に関係なしに、スレッド ツールに保持されるアイドル状態のスレッドの総数を取得および設定します。
負の数を指定するか、スレッド プールのアクティブなスレッドの最大数 (GetMaxThreads で取得) を超える数を指定すると、 SetMinThreads から false が返され、いずれの最小値も変更されません。
注意 アイドル状態のスレッドの数をプロセッサ数未満に設定すると、パフォーマンスが低下する場合があります。アイドル状態のスレッドの数が多いと、システム リソースの負担が大きくなります。全体的なパフォーマンスを最適に維持するために、スレッド数を調整する必要があります。アプリケーションの動作の量が時間によって大きく異なる場合は、アイドル状態のスレッド数を少し増やすだけで、スループットが大幅に向上する場合があります。
使用例
[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 名前空間 | GetMinThreads | GetMaxThreads | GetAvailableThreads