我正在尝试创建一个显示任务管理器性能数据的网页。所以我这样使用PerformanceCounters
:
using (PerformanceCounter pCounter = new PerformanceCounter())
{
pCounter.CategoryName = "Processor";
//pCounter.CategoryName = "Processor Information"; // Even this didn't work...
pCounter.CounterName = "% Processor Time";
pCounter.InstanceName = "_Total";
// will always start at 0
pCounter.NextValue();
System.Threading.Thread.Sleep(1000);
(int)pCounter.NextValue(); // This does not match the task manager reading. Why?
using (ManagementObject Mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'"))
{
float sp = (uint)(Mo["CurrentClockSpeed"]) / 1000f; // This dpes not match the task manager reading. Why?
}
}
我在上面的代码中添加了注释,用于指定数据不匹配的位置。 基本上CPU使用率和CPU速度与任务管理器读数不匹配。 那怎么样?