System.Diagnostics.PerformanceCounter myCounter = new System.Diagnostics.PerformanceCounter();
myCounter.CategoryName = "Processor";
myCounter.CounterName = "% Processor Time";
myCounter.InstanceName = "_Total";
OutputSample(myCounter.NextSample());
private static void OutputSample(CounterSample s)
{
Console.WriteLine("\r\n+++++++++++");
Console.WriteLine("Sample values - \r\n");
Console.WriteLine(" BaseValue = " + s.BaseValue);
Console.WriteLine(" CounterFrequency = " + s.CounterFrequency);
Console.WriteLine(" CounterTimeStamp = " + s.CounterTimeStamp);
Console.WriteLine(" CounterType = " + s.CounterType);
Console.WriteLine(" RawValue = " + s.RawValue);
Console.WriteLine(" SystemFrequency = " + s.SystemFrequency);
Console.WriteLine(" TimeStamp = " + s.TimeStamp);
Console.WriteLine(" TimeStamp100nSec = " + s.TimeStamp100nSec);
Console.WriteLine("++++++++++++++++++++++");
}

为什么nextvalue的返回值是0呢,如何取到性能计数器里看到的值
------解决思路----------------------
NextSample是未计算的原始值,一般情况用NextValue比较方便。NextValue为0是因为它的结果是两次调用之间的平均值,只调用一次就是0。如果用一个定时器每秒执行一次NextValue,得到的每秒平均值看起来就对了。