c#资源监视器获取网络活动值
时间: 2023-09-30 21:12:17 浏览: 52
要获取C#资源监视器中的网络活动值,可以使用System.Net.NetworkInformation命名空间中的类。具体步骤如下:
1. 引入System.Net.NetworkInformation命名空间。
2. 创建一个NetworkInterface对象,该对象表示计算机上的网络接口。
3. 调用NetworkInterface.GetIPv4Statistics()方法获取该接口的IPv4网络统计信息。
4. 从IPv4统计信息中获取网络活动值。
下面是一个示例代码:
```
using System;
using System.Net.NetworkInformation;
class Program
{
static void Main(string[] args)
{
NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in interfaces)
{
IPv4InterfaceStatistics ipv4Stats = ni.GetIPv4Statistics();
Console.WriteLine("Bytes sent: {0}", ipv4Stats.BytesSent);
Console.WriteLine("Bytes received: {0}", ipv4Stats.BytesReceived);
}
}
}
```
该代码会输出每个网络接口的发送和接收字节数。你可以根据自己的需求修改代码以获取其他网络统计信息。