C# 检测电脑CPU与内存

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);
   //}
}

你可能感兴趣的:(C#,学习,c#,开发语言,java)