在RichTextBox中显示CPU使用情况

时间:2014-10-09 01:46:56

标签: c# richtextbox cpu counter

我已将实例定义为:

PerformanceCounter perf =
    new PerformanceCounter("Processor", "% Processor Time", "_Total", ".");

我希望此信息显示在RichTextBox中。这就是我调用实例的方式:

richTextBox1.AppendText("CPU Load: {0}", PerformanceCouner.NextValue());

但是" NextValue"总是附加一个错误说:

  

CPU_information.PerformanceCounter不包含NextValue的定义。

我真的需要一些帮助。感谢。

1 个答案:

答案 0 :(得分:3)

您试图在PerformanceCounter类本身上调用方法,而不是实例。

相反,您需要引用您创建的PerformanceCounter实例:

perf.NextValue();

您的代码仍然无法编译,因为您忘记了string.Format

richTextBox1.AppendText(string.Format("CPU Load: {0}", perf.NextValue()));