using System.Diagnostics;
PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
while (true)
{
System.Threading.Thread.Sleep(1000);
Console.WriteLine("电脑CPU使用率:" + cpuCounter.NextValue() + " %");
Console.WriteLine("电脑可使用内存:" + ramCounter.NextValue() + "MB");
Console.WriteLine();
//if ((int)cpuCounter.NextValue() > 80)
//{
// System.Threading.Thread.Sleep(1000 * 60);
//}
}