表示 Windows NT 性能计数器组件
命名空间:System.Diagnostics
categoryName
性能计数器关联的性能计数器类别(性能对象)的名称。
counterName
性能计数器的名称。
instanceName
性能计数器类别实例的名称,或者为空字符串 ("")(如果该类别包含单个实例)。
public PerformanceCounter (string categoryName,string counterName,string instanceName);
根据categoryName,counterName,instanceName获得性能情况显示
PerformanceCounter pc=New PerformanceCounter("Processor","% Processor Time","_Total");//这些参数可以获得CPU的使用率
while(true)
{
Thread.Sleep(1000); //等待1s刷新数据
float cpuload = pc.NextValue(); //float形式显示数据
//string cpuload=pc.NextValue.ToString("0.00"); //string形式显示数据
Console.WriteLine("CPU Load="+cpuload+"%."); //百分比现实cpu的使用率
}