Reputation: 323
How can I know the number of IIS threads consumed at a given time by my ASP.NET Web API service?
I can count .NET CLR threads of the running application by the below code snippet:
int number = Process.GetCurrentProcess().Threads.Count;
but my question is about IIS threads.
IIS v8.5, Windows Server 2012
Upvotes: 1
Views: 545
Reputation: 6090
In IIS a service (ASP.NET application) is running using an application pool. So if the name of the application pool is known at runtime, you can determine the number of threads for your application pool:
var applicationPoolName = "YOUR APPLICATION POOL";
using (var serverManager = new Microsoft.Web.Administration.ServerManager())
{
var applicationPool = serverManager.ApplicationPools[applicationPoolName];
var threadsCount = applicationPool
.WorkerProcesses
.Select(p => Process.GetProcessById(p.ProcessId))
.SelectMany(p => p.Threads.Cast<ProcessThread>())
.Count();
}
Upvotes: 2