【发布时间】:2019-09-17 16:47:39
【问题描述】:
这是我之前的question 的下一步。
我正在创建一个 C# WinForm 应用程序,它将显示给定进程(例如:进程名称的 chrome.exe)的网络活动(接收的字节数/发送的字节数)和进程生成的速度(以兆比特/秒为单位)。
在使用性能计数器 IO Read Bytes/sec 和 IO Read Bytes/sec 时,会显示 I/O 读取和写入字节,而不是 “发送和接收字节”。
PS:I/O 计算进程生成的所有文件、网络和设备 I/O 字节。但是,我只想要特定进程生成的网络字节。
我只想检索 Bytes Received 和 Bytes Sent。但是,不知道使用什么计数器来获取进程的这些字节。
我已经为此目的搜索了这些链接,但没有用:
- C# Resource Monitor get network activity values
- Retrieve process network usage
- Missing network sent/received
- Need "Processes with Network Activity" functionality in managed code - Like resmon.exe does it
这是尝试过的 Process 的性能计数器代码:
PerformanceCounter bytesReceived = new PerformanceCounter("Process", "IO Read Bytes/sec");
PerformanceCounter bytesSent = new PerformanceCounter("Process", "IO Write Bytes/sec");
string ProcessName = "chrome";
bytesReceived.InstanceName = ProcessName;
bytesSent.InstanceName = ProcessName;
问题:我如何才能获取网络活动的进程生成的接收和发送字节数。
【问题讨论】:
-
我想要使用
PerformanceCounter的解决方案。 -
在仔细阅读了您提供的链接和this one 之后,我很确定
PerformanceCounter类是不可能的,因为它仅从一组或多或少预定义的受限集合中提取计数器。在我的本地系统上列出可用的计数器表明没有机会在不包括磁盘 I/O 的情况下定位某个进程。 -
@JanWichelmann 你的意思是
PerformanceCounter不可能吗?如果是,那么我如何才能实现它。
标签: c# .net process performancecounter