开发者

PerformanceCounterCategory to string value

I am trying to retrieve the value of my readyboost cache I wrote the following code but it says the value does not exist

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

Spelling is correct, I can see the object following this code

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

Th开发者_C百科anks in advance


the parameter of GetCounters should be the instance name of the performance Counter. change your code as follows:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜