多处理器和PerformanceCounter C#

Aar*_*zar 5 c# processor performancecounter

我正在试图弄清楚如何收集计算机上每个处理器的当前使用百分比.如果我使用"System.Environment.ProcessorCount;" 我可以获得计算机上的处理器数量,它当前返回"2".我要么不知道我在找什么,要么在网上没有太多关于此的信息.

以下是我目前用于获取所有处理器总当前使用百分比的代码.

protected PerformanceCounter cpuCounter = new PerformanceCounter("processor", "% Processor Time", "_Total");
public string getCurrentCpuUsage()
{
    return cpuCounter.NextValue() + "%";
}
Run Code Online (Sandbox Code Playgroud)

感谢您的任何帮助,

亚伦

Hen*_*man 7

对于第一个处理器,请使用

protected PerformanceCounter cpuCounter = 
  new PerformanceCounter("processor", "% Processor Time", "0");
Run Code Online (Sandbox Code Playgroud)

依此类推,最多(Environment.ProcessorCount-1).ToString()


Aar*_*zar 5

由于我留下了最初的问题,我碰巧在我的 Windows 7 计算机上找到了 Windows 性能监视器 ( C:\Windows\system32\perfmon.msc)。如果右键单击主窗口上的图表并选择“添加计数器”,则将显示一个可能用作 PerformanceCounter 中参数的字符串列表,几乎涵盖了人们想要监视的所有内容。