C#性能计数器值与任务管理器中的实际数据不匹配

时间:2015-02-15 14:57:04

标签: c# performancecounter

我正在尝试创建一个显示任务管理器性能数据的网页。所以我这样使用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速度与任务管理器读数不匹配。 那怎么样?

0 个答案:

没有答案
相关问题