我想制作一个与 Windows 任务管理器中使用的控件非常相似的控件,以显示 CPU 性能,类似于不断变化的垂直 Guage
最佳答案
您可以使用 WMI 通过 ManagementObjectSearcher
获取 CPU 使用值
为了获得值(value),你做这样的事情
var info = ManagementObjectSearcher(@"\\localhost\root\CIMV2","SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name=\"_Total\"");
ManagementObject queryObj = info.Get().Cast<ManagementObject>().First();
var cpuUsage = Convert.ToInt32(queryObj["PercentIdleTime"]);
或者,您可以改用 System.Diagnostics PerformanceCounter
PerformanceCounter cpu = new PerformanceCounter(){
CategoryName = "Processor",
CounterName = "% Processor Time",
InstanceName = "_Total"
};
var yourCpuUsageValue = cpu.NextValue();
关于c# - 如何在 WPF 中进行 CPU 使用控制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9242970/