我需要一种简单的方法来检查主机 PC 的 CPU 有多少内存和速度。我尝试了 WMI 但是我正在使用的代码
private long getCPU()
{
ManagementClass mObject = new ManagementClass("Win32_Processor");
mObject.Get();
return (long)mObject.Properties["MaxClockSpeed"].Value;
}
抛出空引用异常。此外,WMI 查询有点慢,我需要进行一些查询才能获得所有规范。有没有更好的办法?
最佳答案
http://dotnet-snippets.com/dns/get-the-cpu-speed-in-mhz-SID575.aspx
using System.Management;
public uint CPUSpeed()
{
ManagementObject Mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'");
uint sp = (uint)(Mo["CurrentClockSpeed"]);
Mo.Dispose();
return sp;
}
RAM 可以在这个 SO 问题中找到:How do you get total amount of RAM the computer has?
关于c# - 如何在 C# 中获取 CPU 速度和总物理内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3017206/