ThreadPool.GetAvailableThreads Method (Int32, Int32)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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

Namespace:   System.Threading
Assembly:  mscorlib (in mscorlib.dll)

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


Type: System.Int32

The number of available worker threads.

Type: System.Int32

The number of available asynchronous I/O threads.

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.

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

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

.NET Framework
Available since 1.1
Return to top