System.dll中出现未处理的“System.InvalidOperationException”类型异常

时间:2015-07-02 04:58:37

标签: c#

我正在执行以下代码:

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());
    }
}

我得到了这个例外。

System.dll中出现未处理的“System.InvalidOperationException”类型异常 附加信息:指定类别中不存在“英特尔(R)82579V千兆网络连接”实例。

我已经使用windows perfmon工具测试了参数,它正在工作,但在代码中它给出异常。

任何人都可以帮忙..

1 个答案:

答案 0 :(得分:1)

您是否检查过姓名拼写是否正确?即使有一个小错误,这很可能不会奏效。

要检查此类别中存在哪些名称,请尝试(按照此处的建议:https://stackoverflow.com/a/29270209/1648463

PerformanceCounterCategory category = new PerformanceCounterCategory("Network Interface");
String[] instancename = category.GetInstanceNames();

foreach (string name in instancename)
{
    Console.WriteLine(name);
}

例如,我计算机上网络接口的现有名称之一是

Intel[R] 82579LM Gigabit Network Connection

(用括号代替圆括号)。

相关问题