ThreadPool.GetAvailableThreads(Int32, Int32) Metode

Definisi

Mengambil perbedaan antara jumlah maksimum utas kumpulan utas yang dikembalikan oleh GetMaxThreads(Int32, Int32) metode , dan angka yang saat ini aktif.

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)

Parameter

workerThreads
Int32

Jumlah utas pekerja yang tersedia.

completionPortThreads
Int32

Jumlah utas I/O asinkron yang tersedia.

Contoh

Contoh berikut menampilkan jumlah utas pekerja dan utas I/O yang tersedia saat aplikasi sederhana dimulai.

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

Keterangan

Saat GetAvailableThreads dikembalikan, variabel yang ditentukan oleh workerThreads berisi jumlah utas pekerja tambahan yang dapat dimulai, dan variabel yang ditentukan dengan completionPortThreads berisi jumlah utas I/O asinkron tambahan yang dapat dimulai.

Jika tidak ada utas yang tersedia, permintaan kumpulan utas tambahan tetap diantrekan hingga utas kumpulan utas tersedia.

Berlaku untuk

Lihat juga