ThreadPool.GetAvailableThreads(Int32, Int32) 方法
本文內容
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
擷取 GetMaxThreads(Int32, Int32) 方法所傳回之執行緒集區的執行緒最大數目,與目前作用中數目之間的差異。
public:
static void GetAvailableThreads([Runtime::InteropServices::Out] int % workerThreads, [Runtime::InteropServices::Out] int % completionPortThreads);
public static void GetAvailableThreads(out int workerThreads, out int completionPortThreads);
static member GetAvailableThreads : int * int -> unit
Public Shared Sub GetAvailableThreads (ByRef workerThreads As Integer, ByRef completionPortThreads As Integer)
- workerThreads
- Int32
可用背景工作執行緒的數目。
- completionPortThreads
- Int32
可用非同步 I/O 執行緒的數目。
下列範例會顯示啟動簡單應用程式時可用的背景工作執行緒和 I/O 執行緒數目。
using System;
using System.Threading;
public class Example
{
public static void Main()
{
int worker = 0;
int io = 0;
ThreadPool.GetAvailableThreads(out worker, out io);
Console.WriteLine("Thread pool threads available at startup: ");
Console.WriteLine(" Worker threads: {0:N0}", worker);
Console.WriteLine(" Asynchronous I/O threads: {0:N0}", io);
}
}
// The example displays output like the following:
// Thread pool threads available at startup:
// Worker threads: 32,767
// Asynchronous I/O threads: 1,000
Imports System.Threading
Module Example
Public Sub Main()
Dim worker As Integer = 0
Dim io As Integer = 0
ThreadPool.GetAvailableThreads(worker, io)
Console.WriteLine("Thread pool threads available at startup: ")
Console.WriteLine(" Worker threads: {0:N0}", worker)
Console.WriteLine(" Asynchronous I/O threads: {0:N0}", io)
End Sub
End Module
' The example displays output like the following:
' Thread pool threads available at startup:
' Worker threads: 32,767
' Asynchronous I/O threads: 1,000
傳回時 GetAvailableThreads ,所 workerThreads
指定的變數包含可啟動的額外背景工作執行緒數目,而 所 completionPortThreads
指定的變數則包含可啟動的其他非同步 I/O 執行緒數目。
如果沒有可用的執行緒,其他執行緒集區要求會保持佇列,直到執行緒集區執行緒變成可用為止。
適用於
產品 | 版本 |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |