我有這樣的代碼:C#自動CPU使用率刷新
private void button1_Click(object sender, EventArgs e)
{
PerformanceCounter cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
var unused = cpuCounter.NextValue(); // first call will always return 0
System.Threading.Thread.Sleep(1000);
label1.Text = "Cpu usage: :" + cpuCounter.NextValue() + "%";
label2.Text = "Free ram : " + ramCounter.NextValue() + "MB";
}
怎麼寫程序,而不是通過按下一個按鈕自動更改%的CPU利用率?