ThreadPool.GetAvailableThreads(Int32, Int32) 方法

定義

擷取 GetMaxThreads(Int32, Int32) 方法所傳回之執行緒集區的執行緒最大數目,與目前作用中數目之間的差異。

public static void GetAvailableThreads(out int workerThreads, out int completionPortThreads);

參數

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

備註

傳回時 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

另請參閱