简体   繁体   English

创建PerformanceCounter“ NetworkInterface CurrentBandwidth *”时,C#InvalidOperationException

[英]C# InvalidOperationException when creating PerformanceCounter “NetworkInterface CurrentBandwidth *”

When I try to create an instance of System.Diagnostics.PerformanceCounter class with the following parameters: 当我尝试使用以下参数创建System.Diagnostics.PerformanceCounter类的实例时:

categoryName = NetworkInterface,  
counterName = CurrentBandwidth, 
instanceName = *.

I get an exception System.InvalidOperationException: Instance '*' does not exist in the specified Category. 我收到异常System.InvalidOperationException:实例'*'在指定的类别中不存在。

I don't understand why star sign doesn't work for selecting all the instances in the category. 我不明白为什么星号不能用于选择类别中的所有实例。 In PerfMon it's used and it works. 在PerfMon中,它可以使用并且可以工作。

Any ideas? 有任何想法吗?

the answer is in your question: you want to create an instance, ie. 答案就在您的问题中:您想创建一个实例,即。 one instance. 一个实例。 PercormanceCounter does not return a collection of counters, which would be required when you want to select with a wildcard. PercormanceCounter不返回计数器的集合,当您要使用通配符进行选择时,这是必需的。

to enumerate all instances, see here: https://stackoverflow.com/a/1305159/3961759 要枚举所有实例,请参见此处: https : //stackoverflow.com/a/1305159/3961759

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM