ThreadPool.GetMinThreads(Int32, Int32) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
스레드 만들기 및 소멸을 관리하기 위한 알고리즘으로 전환하기 전에 새 요청이 이루어지면 스레드 풀이 요청 시 만드는 최소 스레드 수를 검색합니다.
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부터 스레드 풀은 처리량을 최적화하기 위해 스레드를 만들고 삭제하며, 이는 시간 단위당 완료되는 작업 수로 정의됩니다. 스레드가 너무 적으면 사용 가능한 리소스를 최적으로 사용하지 못할 수 있지만 스레드가 너무 많으면 리소스 경합이 증가할 수 있습니다.
메모
수요가 낮으면 실제 스레드 풀의 스레드 수가 최소값 이하로 떨어질 수 있습니다.