Multiple Processors and PerformanceCounter C#

有些话、适合烂在心里 提交于 2019-11-28 04:08:44

问题


I'm trying to figure out how to gather the current usage percentage of each individual processor on my computer. If I use "System.Environment.ProcessorCount;" I can get the number of processors on my computer and it currently returns "2". I either don't know what I'm looking for or there isn't very much info about this on the internet.

The following is the code I'm currently using to get the total current usage percentage of all processors combined.

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

Thank you for any help,

Aaron


回答1:


For the first processor, use

protected PerformanceCounter cpuCounter = 
  new PerformanceCounter("processor", "% Processor Time", "0");

And so on, up to (Environment.ProcessorCount-1).ToString()




回答2:


Since I left my original question I happened to find the Windows Performance Monitor (C:\Windows\system32\perfmon.msc) on my Windows 7 computer. If one right-clicks the graph on the main window and chooses "Add Counters" then a list of possible strings to use as parameters in the PerformanceCounter is displayed for just about everything one would want to monitor.



来源:https://stackoverflow.com/questions/2232801/multiple-processors-and-performancecounter-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!