计数器不是单个实例,需要指定实例名称 [英] Counter is not single instance, an instance name needs to be specified

查看:109
本文介绍了计数器不是单个实例,需要指定实例名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发性能监视控制台应用程序时,getcategories方法传递了什么?

In developing a performance monitoring console app, what is passed into the getcategories method?:

PerformanceCounter[] pcArr = pc.GetCounters(string instance);

使用无参数重载时,会引发运行时异常:

When using the no param overload, a runtime exception is thrown:

计数器不是单个实例,需要指定实例名称.

Counter is not single instance, an instance name needs to be specified.

此外,如何确定静态实用程序方法还是扩展方法?例如,我可能经常使用某种实用程序方法,但是最好将其添加为扩展方法,这样我就不必一直引用另一个程序集.

Also, how do you decide between a static utility method or an extension method? For example, I may use a certain utility method quite frequently but then it would be best to add that as an extension method so I don't have to reference another assembly all the time.

谢谢

推荐答案

您需要在GetCounters()方法中指定实例名称.如果您在控制面板"->管理工具"下查看性能监视器.查看实例"列.这就是您需要提供给该方法的内容.具有相同实例名称的所有计数器将被返回.如果"---"列中没有任何内容,则它是单个实例,您无需传递任何内容.

You need to specify an instance name in the GetCounters() method. If you look at your perfomance monitor under Control Panel -> Administrative Tools. Look at the 'Instance' column. That's what you need to give to the method. All counters with the same instance name will be returned. If there is nothing in that column '---' then it's a single instance and you don't need to pass anything.

据我所知,实例"的原因可能是要监视多个设备".在处理器类别下,您可以有多个实例,每个处理器一个,我的具有双核,因此也有一个'0','1'和'_Total'.内存是单个实例(至少在我的机器上).

As far as I can tell, the reason for 'instances' is there may be multiple 'devices' to monitor. Under the processer category you could have multiple instances, one for each processor, mine has a dual core, so has a '0', '1', and '_Total'. Memory is single instance (at least on my machine).

我会分别询问您的静态实用程序方法或扩展方法问题.

I would ask your static utility method or extension method question separately.

这篇关于计数器不是单个实例,需要指定实例名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆