PerformanceCounterCategory转换为字符串值

本文关键字:字符串 转换 PerformanceCounterCategory | 更新日期: 2023-09-27 18:09:59

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

PerformanceCounterCategory转换为字符串值

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