运行计数器具有4个特性
浏览可用运行计数器,可以通过进入Control Panel(控制面板) | Administrative Tools(管理工具) | Performance(性能) 点击Add(添加)来实现。
下面的程序给本地机器初始化了一个运行计数器来监控% Processor Time计数器。
Dim perfCounter As New System.Diagnostics.PerformanceCounter()
Dim loopCount As Integer
perfCounter.CategoryName = "Processor"
perfCounter.CounterName = "% Processor Time"
perfCounter.InstanceName = "_Total"
For loopCount = 1 To 100
Debug.WriteLine(perfCounter.NextValue.ToString())
Next
perfCounter.Close()
当完成时,调用PerformanceCounter里的Close方法是很重要的,因为它用到的系统资源是必须要被释放出来的。