PerformanceCounter 基本介绍以及示例方法

来源:互联网 发布:js插件是什么 编辑:程序博客网 时间:2024/05/27 14:14

一 PerformanceCounter 基本介绍
1 简单介绍
表示 Windows NT 性能计数器组件
命名空间:System.Diagnostics
程序集:System(在 system.dll 中)
2 构造函数(只介绍本文要用到的)
PerformanceCounter (String, String, String)
功能:
初始化 PerformanceCounter 类的新的只读实例,
并将其与本地计算机上指定的系统性能计数器或自定义性能计数器及类别实例关联
参数说明:
public PerformanceCounter (
 string categoryName,
 string counterName,
 string instanceName
)
categoryName
性能计数器关联的性能计数器类别(性能对象)的名称。
counterName
性能计数器的名称。
instanceName
性能计数器类别实例的名称,或者为空字符串 ("")(如果该类别包含单个实例)。
二 示例方法:
需要引用命名空间

1 获取性能计数器类别列表
虽然系统中有很多可用的计数器类别,但与之交互最频繁的可能是“Cache”(缓存)、“Memory”(内存)、
“Objects”(对象)、“PhysicalDisk”(物理磁盘)、“Process”(进程)、“Processor”(处理器)、
“Server”(服务器)、“System”(系统
)和“Thread”(线程)等类别

 

2 获取性能计数器类别下的实例的名称实例下的性能计数器的名称

 

3 根据categoryName,counterName,instanceName获得性能情况显示

 

4 调用方法3显示cpu使用率

原创粉丝点击