How to get CPU usage for more than 2 cores?

前端 未结 5 448
甜味超标
甜味超标 2020-12-03 15:57

I try to get in my program CPU usage divided by a cores. Now I use the PerformanceCounter and changing the InstanceName between 0 and 1 I have the data from 2 cores.

5条回答
  •  时光说笑
    2020-12-03 16:14

    foreach (var item in new System.Management.ManagementObjectSearcher("Select NumberOfLogicalProcessors from Win32_Processor").Get())
        coreCount += int.Parse(item["NumberOfLogicalProcessors"].ToString());
    
    PerformanceCounter[] pc = new PerformanceCounter[coreCount];
    
    for (int i = 0; i < coreCount; i++)
        pc[i] = new PerformanceCounter("Processor", "% Processor Time", i.ToString());
    

提交回复
热议问题