PerformanceCounterCategory为字符串值

时间:2011-09-26 23:55:18

标签: c# system.diagnostics

我正在尝试检索我的readyboost缓存的值我编写了以下代码,但它说该值不存在

System.Diagnostics.PerformanceCounterCategory pc;
            pc = new System.Diagnostics.PerformanceCounterCategory("ReadyBoost Cache");
            pc.GetCounters("Bytes cached");
            MessageBox.Show(Convert.ToString(pc));

拼写正确,我可以看到此代码后的对象

http://msdn.microsoft.com/en-us/library/2fh4x1xb(v=vs.71).aspx

提前致谢

1 个答案:

答案 0 :(得分:1)

GetCounters的参数应该是性能计数器的实例名称。按如下方式更改您的代码:

    System.Diagnostics.PerformanceCounterCategory pc;
    pc = new System.Diagnostics.PerformanceCounterCategory("ReadyBoost Cache");
    foreach (PerformanceCounter counter in pc.GetCounters())
    {
        if (counter.CounterName == "Bytes cached")
        {
            //to do
        }
    }