Bewerken

Share via


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.

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)

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.

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

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

See also