[英]An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll
I was executing code below : 我正在执行以下代码:
class Program
{
static void Main(string[] args)
{
PerformanceCounter performanceCounter = new PerformanceCounter("Network Interface", "Bytes Sent/sec", "Intel(R) 82579V Gigabit Network Connection");
Console.WriteLine(performanceCounter.NextValue().ToString());
}
}
I'm getting this exception. 我收到这个例外。
An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll Additional information: Instance 'Intel(R) 82579V Gigabit Network Connection' does not exist in the specified Category. System.dll中发生了类型为'System.InvalidOperationException'的未处理异常。其他信息:指定类别中不存在实例'Intel(R)82579V千兆网络连接'。
I have tested the parameters with windows perfmon tool , it was working but in code its giving exception. 我已经使用Windows perfmon工具测试了参数,它正在工作,但是在代码中给出了异常。
Can anybody please help.. 有人可以帮忙吗..
Have you checked if the name is spelled correctly? 您是否检查过拼写正确的名称? Even with a minor error, this most likely won't work. 即使有小错误,这也很可能行不通。
To check which names exist in this category, try (as suggested here: https://stackoverflow.com/a/29270209/1648463 ) 要检查此类别中存在哪些名称,请尝试(如此处建议的那样: https : //stackoverflow.com/a/29270209/1648463 )
PerformanceCounterCategory category = new PerformanceCounterCategory("Network Interface");
String[] instancename = category.GetInstanceNames();
foreach (string name in instancename)
{
Console.WriteLine(name);
}
For example, one of the existing names for network interfaces on my computer is 例如,我计算机上网络接口的现有名称之一是
Intel[R] 82579LM Gigabit Network Connection
(with brackets instead of round brackets). (使用方括号代替圆括号)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.