![](/img/trans.png)
[英]'System.InvalidOperationException' occurred in System.dll
[英]An unhandled exception of type 'System.InvalidOperationException' occurred in System.dll
我正在執行以下代碼:
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'的未處理異常。其他信息:指定類別中不存在實例'Intel(R)82579V千兆網絡連接'。
我已經使用Windows perfmon工具測試了參數,它正在工作,但是在代碼中給出了異常。
有人可以幫忙嗎..
您是否檢查過拼寫正確的名稱? 即使有小錯誤,這也很可能行不通。
要檢查此類別中存在哪些名稱,請嘗試(如此處建議的那樣: 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
(使用方括號代替圓括號)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.