共用方式為


ThreadPool.GetAvailableThreads(Int32, Int32) 方法

定義

擷取 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 執行緒數目。

如果沒有可用的執行緒,其他執行緒集區要求會保持佇列,直到執行緒集區執行緒變成可用為止。

適用於

另請參閱