[STAThread]
public static void Main()
{
string path = AppDomain.CurrentDomain.BaseDirectory; //获取基目录
PerformanceCounter pc
= new PerformanceCounter(CategoryName, CounterName, InstanceName);
while (true)
{
Thread.Sleep(1000); // wait for 1 second
float cpuLoad = pc.NextValue();
Say("CPU load = " + cpuLoad + " %." );
}
}
private const string CategoryName = "Processor";
private const string CounterName = "% Processor Time";
private const string InstanceName = "_Total";
private static void Say(string txt)
{
Console.WriteLine(txt);
}
private static void Say()
{
Say("");
}