我有一个问题:我的性能程序总是显示 0% CPU 使用率...
我添加了 1 个名为 Text value 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();
}
}