我这样做的,可是显示为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();
}
}

解决方案 »

  1.   

    把这段代码加到tiemer的事件中
      

  2.   

    呵呵 今天看来上班的公司不多啊这个问题是酱紫滴把
    PerformanceCounter pc = new PerformanceCounter(CategoryName, CounterName, InstanceName);
    float cpuLoad = pc.NextValue();
    label24.Text = cpuLoad.ToString();加入到Timer的Ticker事件中 让他不停的刷就好了
      

  3.   

    我这样做了,可是显示不是0,就是100,怎么回事啊?private void timer1_Tick(object sender, EventArgs e)
    {
    PerformanceCounter pc = new PerformanceCounter("Processor", "% Processor Time", "_Total");
    label2.Text = pc.NextValue().ToString();
    }
      

  4.   

    sorry那天写的不仔细pc 不要在timer中不停的new 只需要声明一个全局变量的pc 然后在timer中不停的调用
    NextValue().ToString();