问题描述
我正在尝试向正在使用的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计数器正常工作,但是我不知道要为最后两个网络接口的实例名称添加什么. /p>
谢谢.
以下是一些示例代码,这些示例如何遍历网络接口;
PerformanceCounterCategory category = new PerformanceCounterCategory("Network Interface");
String[] instancename = category.GetInstanceNames();
foreach (string name in instancename)
{
Console.WriteLine(name);
}
现在,通过使用 PerformanceCounterCategory ,您可以获取实例名称,然后使用 GetInstanceNames 在PerformanceCounter中使用.
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. 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). 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.
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.
这篇关于用于网络接口性能计数器的C#实例名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!