我正在构建一个快速进程cpu使用检测程序,我在这里遇到了PerformanceCounter的一个小问题。如果我添加了一个PerformanceCounter对象,并在GUI上的属性分隔符上放置了正确的值,我就可以做到这一点。但是这个工作只适用于一个固定的过程。所以我想做的是一种动态的方法来获得这些值。看: Return New PerformanceCounter返回总是0.0
修正代码
try var uptime = new PerformanceCounter("System", "System Up Time");var uptime = new PerformanceCounter("System", "System Up Time");
例外是"Input String was not in Correct
string counter = "IO Reads/sec";for (int i = 0; i < 60; i++) using (PerformanceCounterperfCounter = new PerformanceCounter(category, counter, instance)) float value = perfCounter.NextValue
以下代码为当前区域设置提供了正确的结果,但要打开性能计数器,我还需要计数器的类别名称(请参阅PerformanceCounter类的构造函数)以及实例名称: Console.WriteLine(buffer.ToString());
var counter = new PerformanceCounter