[英]C# Instance Name to Use For Network Interface Performance Counter
I'm trying to add some system monitoring functions to a WPF app I am working on and I would like to add a bandwidth use monitor. 我正在尝试向正在使用的WPF应用程序添加一些系统监视功能,我想添加一个带宽使用监视器。 Right now I have a CPU and a RAM counter working but I can't figure out what to use for the Performance Counter instance name (sorry if that isn't the correct term).
现在我有一个CPU和一个RAM计数器,但是我不知道要为Performance Counter实例名称使用什么(抱歉,如果这不是正确的术语)。 This is what I'm using so far:
到目前为止,这是我正在使用的:
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", );
I have strings that update every 1 second using a timer tick method that updates my WPF labels and the RAM and the CPU counters work but I don't know what to put for the instance names for the last two network interfaces. 我有使用计时器滴答方法每1秒更新一次的字符串,该计时器滴答方法更新了我的WPF标签,并且RAM和CPU计数器正常工作,但是我不知道要为最后两个网络接口的实例名称添加什么。
Thanks in advance. 提前致谢。
Here is some sample code how to iterate through the Network Interfaces; 这是一些示例代码,如何遍历网络接口;
PerformanceCounterCategory category = new PerformanceCounterCategory("Network Interface");
String[] instancename = category.GetInstanceNames();
foreach (string name in instancename)
{
Console.WriteLine(name);
}
By utilizing the PerformanceCounterCategory , you can now obtain the Instance Names, and then use in your PerformanceCounter(s) using GetInstanceNames . 通过使用PerformanceCounterCategory ,您现在可以获得实例名称,然后使用GetInstanceNames在PerformanceCounter中使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.