我正在使用此代码来获取接收和发送的应用程序字节:
long BytesSent = 0;
long BytesReceived = 0;
private void timerPerf_Tick(object sender, EventArgs e)
{
if (!NetworkInterface.GetIsNetworkAvailable())
return;
NetworkInterface[] interfaces
= NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in interfaces)
{
BytesSent += ni.GetIPv4Statistics().BytesSent;
BytesReceived += ni.GetIPv4Statistics().BytesReceived;
this.label2.Text = BytesSent.ToString();
this.label3.Text = BytesReceived.ToString();
}
}
此方法每秒调用一次。问题在于它获取所有计算机数据,而不是当前应用程序接收和发送的字节。知道是什么问题吗?