ThreadPool.GetAvailableThreads(Int32, Int32) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
检索由 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 线程数。
如果没有可用的线程,则其他线程池请求将保持排队状态,直到线程池线程变为可用。