在RichTextBox中显示CPU使用情况

本文关键字:用情 情况 CPU 显示 RichTextBox | 更新日期: 2023-09-27 18:26:03

我已将实例定义为:

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

我希望这些信息显示在RichTextBox中。这就是我如何调用实例:

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

但"NextValue"总是附带一个错误,上面写着:

CPU_information.PerformanceCounter不包含NextValue的定义。

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

在RichTextBox中显示CPU使用情况

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

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

perf.NextValue();

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

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