使用PerformanceCounterCategory类,PerformanceCounter类。
获取Network Interface性能计数器实例。
PerformanceCounterCategory category = new PerformanceCounterCategory("Network Interface");
获取速度
adapter.dlCounter = new PerformanceCounter("Network Interface", "Bytes Received/sec", name);
在调试中:PerformanceCounterCategory category = new PerformanceCounterCategory("Network Interface");
语句报错:“无法加载计数器名称数据,因为从注册表读取的索引“”无效。”
解决方法:
先查看性能监视器( 命令:perfmon ), 会发现确实有错。
cmd 输入: lodctr /r 即可修复。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 try 2 { 3 #region 输出全部"categoryName性能计数器类别名称" 4 PerformanceCounterCategory[] ArrayCategories =