6
我正在尋找一種更好的方式來獲取來自多個系統(表示不同的CPU等)的WMI百分比的CPU負載。 我的代碼正在工作,但我認爲有一個更好的方法來克服所有CPU使用率的百分比。WMI查詢-CPU LoadPercentage
任何想法?
預先感謝您!
SelectQuery queryCpuUsage = new SelectQuery("SELECT * FROM Win32_Processor");
ManagementObjectSearcher cpuUsage = new ManagementObjectSearcher(scope, queryCpuUsage);
ManagementObjectCollection cpuUsageCollection = cpuUsage.Get();
foreach (ManagementObject queryObj in cpuUsageCollection)
{
iCPU++;
calcCPU = Convert.ToInt32(queryObj["LoadPercentage"]);
perCPU = perCPU + calcCPU;
}
perCPU = perCPU/iCPU;
cpuUsageCollection.Dispose();
Console.WriteLine("LoadPercentage CPU: {0}", perCPU);