ThreadPool.SetMinThreads メソッド
アセンブリ: mscorlib (mscorlib.dll 内)

Public Shared Function SetMinThreads ( _ workerThreads As Integer, _ completionPortThreads As Integer _ ) As Boolean
Dim workerThreads As Integer Dim completionPortThreads As Integer Dim returnValue As Boolean returnValue = ThreadPool.SetMinThreads(workerThreads, completionPortThreads)
戻り値
変更が成功した場合は true。それ以外の場合は false。

スレッド プール内にアイドル状態のスレッドを保持するのは、スレッド プールのスレッドが要求された場合に、要求にすばやく応じるためです。ワーカー スレッドおよび非同期 I/O スレッドに対して、別個に最少数が保持されます。アイドル状態のスレッドが最小数を超えると、システム リソースを節約するために余分なスレッドが終了されます。アイドル状態のスレッドの保持はバックグラウンド タスクが担当します。
![]() |
---|
アイドル状態のスレッドの数をプロセッサ数未満に設定すると、パフォーマンスが低下する場合があります。アイドル状態のスレッドの数が多いと、システム リソースの負担が大きくなります。全体的なパフォーマンスを最適に維持するために、必要に応じてスレッド数を調整します。アプリケーションの動作の量が時間によって大きく異なる場合は、アイドル スレッドの数を少し増やすだけで、スループットが大幅に向上する場合があります。 |

アイドル状態のワーカー スレッドの最小数を 4 に設定し、アイドル状態の非同期 I/O 完了スレッドの最小数については元の値を保持する例を次に示します。
Imports System 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
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. } } }
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. } }
import System.*; import System.Threading.*; import System.Threading.Thread; public class Test { public static void main(String[] args) { int minWorker = 0; int minIOC = 0; // 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. } } //main } //Test

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- ThreadPool.SetMinThreads メソッドのページへのリンク