Is this the right way to get the grand total of processors with WMI on a multi-cpu system?
I don't have access to a multi-socketed computer, so I am unsure if the follo开发者_开发问答wing will get the grand total of processors and logical processors. I assume ManagementObjectSearcher will return an instance for each socketed CPU and I just keep a running total?
int totalCPUs = 0;
int totalLogicalCPUs = 0;
ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_ComputerSystem");
foreach (var mo in mos.Get())
{
string num = mo.Properties["NumberOfProcessors"].Value.ToString();
totalCPUs += Convert.ToInt32(num);
num = mo.Properties["NumberOfLogicalProcessors"].Value.ToString();
totalLogicalCPUs += Convert.ToInt32(num);
}
It will only return 1 instance of Win32_ComputerSystem. From the documentation:
If a computer system has two physical processors each containing two logical processors, then the value of NumberOfProcessors is 2 and NumberOfLogicalProcessors is 4. The processors may be multicore or they may be hyperthreading processors.
精彩评论