Search code examples
c#.netwindowsservice

Getting CPU usage of a specific Service in C#


I want to know the CPU usage of a specific service in C#.

PerformanceCounter works fine with process:

PerformanceCounter counter = new PerformanceCounter("Process", "% Processor Time", "myprocess", true);  
double result = counter.NextValue();

but not with services:

PerformanceCounter counter = new PerformanceCounter("Service", "% Processor Time", "myservice", true);  
double result = counter.NextValue();

Solution

  • The correct name for the performance counter would be

    PerformanceCounter counter = new PerformanceCounter("Process", "% Processor Time", "ACService", true);