performancecounter - 为什么系统正常运行时间的性能计数器需要 2 次调用 NextValue?
问题描述
这是您获取系统正常运行时间的性能计数器的方式:
public TimeSpan GetSystemUptime(){
PerformanceCounter upTime = new PerformanceCounter("System", "System Up Time");
upTime.NextValue();
return TimeSpan.FromSeconds(upTime.NextValue());
}
NextValue 必须被调用两次,因为它在第一次调用时为 0。但我不明白为什么它使用必须读取两次的计数器。我知道像 CPU Usage [new PerformanceCounter("Processor Information", "% Processor Time", "_Total")] 这样的东西需要 2 个值,因为它计算的是一段时间内的平均值。但是为什么在计算系统正常运行时间时需要测量 2 次?您是否只需要测量当前时间并将其与启动时间进行比较?
解决方案
推荐阅读
- firebase - 在 Firebase 实时数据库中查询
- python - pygame.error:文件不是运行 Mac os Monteray 的 m1 Mac 上的 Windows BMP 文件
- flutter - 在 ListTile 中,onTap 不起作用,显示 Failed Assertion
- r - 使用索引对切片高维 R 数组
- javascript - 在 React 中遍历数组中的数组
- javascript - 如何将参数传递为变量onclick和vue js
- regex - 谷歌表格获取行中的最后一个非空单元格
- python - 计算满足数据集中条件的元素 - Python/pandas
- r - 用于测试集的 R randomForest localImp
- python - 在 Javascript 变量中使用 Python 值