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

…衆ロ難τιáo~ 提交于 2019-12-11 06:55:12

问题


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.

Thanks


回答1:


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.

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.



来源:https://stackoverflow.com/questions/390166/counter-is-not-single-instance-an-instance-name-needs-to-be-specified

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!