这是在多 CPU 系统上获取带有 WMI 的处理器总数的正确方法吗?
我无法访问多插槽计算机,因此我不确定以下计算机是否会获得处理器和逻辑处理器的总数。我假设 ManagementObjectSearcher 将为每个插槽的 CPU 返回一个实例,而我只保留运行总数?
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);
}
I don't have access to a multi-socketed computer, so I am unsure if the following 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它只会返回 1 个 Win32_ComputerSystem 实例。来自文档:
It will only return 1 instance of Win32_ComputerSystem. From the documentation: