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 執行緒數量。
範例
以下範例顯示啟動簡單應用程式時可用的工作執行緒與輸入輸出執行緒數量。
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 執行緒數量。
若無可用執行緒,則額外的執行緒池請求會保留在排隊狀態,直到執行緒池執行緒可用。