ThreadPool.GetAvailableThreads(Int32, Int32) Method

Definition

Retrieves the difference between the maximum number of thread pool threads returned by the GetMaxThreads(Int32, Int32) method, and the number currently active.

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

Parameters

workerThreads
Int32

The number of available worker threads.

completionPortThreads
Int32

The number of available asynchronous I/O threads.

Examples

The following example displays the number of worker threads and I/O threads available when a simple app is started.

C#
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

Remarks

When GetAvailableThreads returns, the variable specified by workerThreads contains the number of additional worker threads that can be started, and the variable specified by completionPortThreads contains the number of additional asynchronous I/O threads that can be started.

If there are no available threads, additional thread pool requests remain queued until thread pool threads become available.

Applies to

Product Versions
.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

See also