我有一個問題:我的表演節目總是顯示0%的CPU使用率...性能計數器,顯示出0%
我已經加入1個標籤稱爲Text值CPU:
下面是代碼:
public partial class Form1 : Form
{
PerformanceCounter cpu = new PerformanceCounter ("Processor", "% Processor Time", "_Total");
public Form1()
{
InitializeComponent();
//string cpu_ussage =
Text.Text = "CPU: " + CPU_TIME();
}
// Provjera Procesa koristeći %
public string CPU_TIME()
{
float cpu_time;
cpu_time = cpu.NextValue();
return Math.Round(Convert.ToDouble(cpu_time.ToString()), 2) + "%";
}
private void timer1_tick(object sender, EventArgs e)
{
Text.Text = "CPU Time:" + CPU_TIME();
}
}
爲什麼'Convert.ToDouble(cpu_time.ToString())'? – Henrik
可能重複嗎? http://stackoverflow.com/questions/2181828/why-the-cpu-performance-counter-kept-reporting-0-cpu-usage – Bridge