簡體   English   中英

用於網絡接口性能計數器的C#實例名稱

[英]C# Instance Name to Use For Network Interface Performance Counter

我正在嘗試向正在使用的WPF應用程序添加一些系統監視功能,我想添加一個帶寬使用監視器。 現在我有一個CPU和一個RAM計數器,但是我不知道要為Performance Counter實例名稱使用什么(抱歉,如果這不是正確的術語)。 到目前為止,這是我正在使用的:

PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes", string.Empty);                        
PerformanceCounter netSentCounter = new PerformanceCounter("Network Interface", "Bytes Received/sec", );
PerformanceCounter netRecCounter = new PerformanceCounter("Network Interface", "Bytes Sent/sec", );

我有使用計時器滴答方法每1秒更新一次的字符串,該計時器滴答方法更新了我的WPF標簽,並且RAM和CPU計數器正常工作,但是我不知道要為最后兩個網絡接口的實例名稱添加什么。

提前致謝。

這是一些示例代碼,如何遍歷網絡接口;

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

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

通過使用PerformanceCounterCategory ,您現在可以獲得實例名稱,然后使用GetInstanceNames在PerformanceCounter中使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM