2014-10-09 45 views
0

内CPU使用率我已经定义了一个实例为:显示一个RichTextBox

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

我希望这些信息被一个RichTextBox中显示。这是我的我打电话实例:

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

但“NextValue”总是说连接到它的错误:

CPU_information.PerformanceCounter不包含NextValue的定义。

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

回答

3

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

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

perf.NextValue(); 

你的代码仍然不能编译,因为你忘了string.Format太:

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