我这样做的,可是显示为0public partial class Form1 : Form
{
.........
private const string CategoryName = "Processor";
private const string CounterName = "% Processor Time";
private const string InstanceName = "_Total";
..........
private void tabPage3_Enter(object sender, EventArgs e)
{
PerformanceCounter pc = new PerformanceCounter(CategoryName, CounterName, InstanceName);
float cpuLoad = pc.NextValue();
label24.Text = cpuLoad.ToString();
}
}
{
.........
private const string CategoryName = "Processor";
private const string CounterName = "% Processor Time";
private const string InstanceName = "_Total";
..........
private void tabPage3_Enter(object sender, EventArgs e)
{
PerformanceCounter pc = new PerformanceCounter(CategoryName, CounterName, InstanceName);
float cpuLoad = pc.NextValue();
label24.Text = cpuLoad.ToString();
}
}
PerformanceCounter pc = new PerformanceCounter(CategoryName, CounterName, InstanceName);
float cpuLoad = pc.NextValue();
label24.Text = cpuLoad.ToString();加入到Timer的Ticker事件中 让他不停的刷就好了
{
PerformanceCounter pc = new PerformanceCounter("Processor", "% Processor Time", "_Total");
label2.Text = pc.NextValue().ToString();
}
NextValue().ToString();