获取c#中特定服务的CPU使用情况

本文关键字:CPU 用情 情况 服务 获取 | 更新日期: 2023-09-27 18:12:39

我想知道c#中特定服务的CPU使用情况。

PerformanceCounter与process:

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

但不包含服务:

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

获取c#中特定服务的CPU使用情况

性能计数器的正确名称应为

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