有些指标需要至少调用两次(第一次初始话);
float cpuStr = pcCpuLoad.NextValue();
cpuStr = pcCpuLoad.NextValue();  // <--再调用一次。

解决方案 »

  1.   

    取样不要太快,间隔1秒或以上比较好。保持一个pcCpuLoad实例,而不是多次创建。
      

  2.   

     CPU占用率的值是随时间变化而变化的,不能只获取一个值,应该在某一时间段内连续获取它的值
    //点击开始按钮
            private void btnStart_Click(object sender, EventArgs e)
            {
                PerformanceCounter pcCpuLoad = new PerformanceCounter("Processor", "% Processor Time", "_Total");
                Thread newThread = new Thread(GetCpuLoad);
                newThread.Start(pcCpuLoad);//启动一个新线程读取CPU占用率
            }        //读取CPU占用率并显示
            private void GetCpuLoad(object obj)
            {
                PerformanceCounter pcCpuLoad = (PerformanceCounter)obj;
                SetLabelTextDelegate setLabelTextDelegate = new SetLabelTextDelegate(SetLabelText);
                while (true) {
                    Thread.Sleep(1000);//每隔一秒读取一次值
                    float cpuLoad = pcCpuLoad.NextValue();
                    this.Invoke(setLabelTextDelegate, new object[] { cpuLoad + "%" });//UI线程显示结果
                }
            }        delegate void SetLabelTextDelegate(string text);
            private void SetLabelText(string text)//label1显示CPU占用率
            {
                label1.Text = text;
            }