PerformanceCounterCategory转换为字符串值



我试图检索我的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

Thanks in advance

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
        }
    }

相关内容

  • 没有找到相关文章

最新更新