对于我的应用程序,我想向用户显示网络带宽。所以,延迟下载将被用户知道..是否有可能向他们展示?在C#中测量网络带宽
4
A
回答
2
试试这个: How to calculate network bandwidth speed in c#。
using System;
using System.Net.NetworkInformation;
using System.Windows.Forms;
namespace InterfaceTrafficWatch
{
/// <summary>
/// Network Interface Traffic Watch
/// by Mohamed Mansour
///
/// Free to use under GPL open source license!
/// </summary>
public partial class MainForm : Form
{
/// <summary>
/// Timer Update (every 1 sec)
/// </summary>
private const double timerUpdate = 1000;
/// <summary>
/// Interface Storage
/// </summary>
private NetworkInterface[] nicArr;
/// <summary>
/// Main Timer Object
/// (we could use something more efficient such
/// as interop calls to HighPerformanceTimers)
/// </summary>
private Timer timer;
/// <summary>
/// Constructor
/// </summary>
public MainForm()
{
InitializeComponent();
InitializeNetworkInterface();
InitializeTimer();
}
/// <summary>
/// Initialize all network interfaces on this computer
/// </summary>
private void InitializeNetworkInterface()
{
// Grab all local interfaces to this computer
nicArr = NetworkInterface.GetAllNetworkInterfaces();
// Add each interface name to the combo box
for (int i = 0; i < nicArr.Length; i++)
cmbInterface.Items.Add(nicArr[i].Name);
// Change the initial selection to the first interface
cmbInterface.SelectedIndex = 0;
}
/// <summary>
/// Initialize the Timer
/// </summary>
private void InitializeTimer()
{
timer = new Timer();
timer.Interval = (int)timerUpdate;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
/// <summary>
/// Update GUI components for the network interfaces
/// </summary>
private void UpdateNetworkInterface()
{
// Grab NetworkInterface object that describes the current interface
NetworkInterface nic = nicArr[cmbInterface.SelectedIndex];
// Grab the stats for that interface
IPv4InterfaceStatistics interfaceStats = nic.GetIPv4Statistics();
// Calculate the speed of bytes going in and out
// NOTE: we could use something faster and more reliable than Windows Forms Tiemr
// such as HighPerformanceTimer http://www.m0interactive.com/archives/2006/12/21/high_resolution_timer_in_net_2_0.html
int bytesSentSpeed = (int)(interfaceStats.BytesSent - double.Parse(lblBytesSent.Text))/1024;
int bytesReceivedSpeed = (int)(interfaceStats.BytesReceived - double.Parse(lblBytesReceived.Text))/1024;
// Update the labels
lblSpeed.Text = nic.Speed.ToString();
lblInterfaceType.Text = nic.NetworkInterfaceType.ToString();
lblSpeed.Text = nic.Speed.ToString();
lblBytesReceived.Text = interfaceStats.BytesReceived.ToString();
lblBytesSent.Text = interfaceStats.BytesSent.ToString();
lblUpload.Text = bytesSentSpeed.ToString() + " KB/s";
lblDownload.Text = bytesReceivedSpeed.ToString() + " KB/s";
}
/// <summary>
/// The Timer event for each Tick (second) to update the UI
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void timer_Tick(object sender, EventArgs e)
{
UpdateNetworkInterface();
}
}
}
+0
虽然这是正确的,但会显示整个网络适配器带宽,而不是针对特定的下载 – 2010-02-05 10:35:05
0
如果是,你通过流下载,那么你可以做的是做一种“米”,从流继承和公开的属性是的求和读取或写入其底层流对象的字节。让仪表封装您用于下载的流对象,然后从流量计对象读取。那么您经常可以检查随时间读取的字节数,以计算消耗的带宽速度。
相关问题
- 1. 测试低带宽网络
- 2. 在C中测量网络流量#
- 3. 检测网络连接带宽(Android)
- 4. C#减少网络带宽使用
- 5. 为什么网络带宽以MHz为单位进行测量?
- 6. Java:测量特定代码段的网络带宽
- 7. 如何可靠地测量进程使用的网络带宽
- 8. 使用Java测量内部网络速度/带宽
- 9. 限制网络带宽在java中
- 10. 优化网络带宽
- 11. 控制网络带宽
- 12. 如何测量互联网带宽
- 13. C插槽来测量带宽
- 14. 如何在swift中测量带宽
- 15. 检测C#中的网络连接速度和带宽使用情况
- 16. 使用PHP测量带宽
- 17. Python或C的网络测量工具
- 18. 不幸的是,____已经停止工作(网络问题?测量带宽)
- 19. 如何测量客户端和服务器之间使用的网络带宽?
- 20. 测量WCF网络流量
- 21. 限制java进程的网络带宽
- 22. 网络丢包延迟带宽模拟
- 23. 监控网络带宽的问题
- 24. WCF和网络带宽限制
- 25. 使用.NET计算网络带宽
- 26. 虚拟盒限制带宽网络
- 27. 谷歌地图低带宽网络JSON
- 28. 移动网络代和带宽
- 29. 利他网络连接带宽估计
- 30. Azure云服务网络带宽
@RomanoZumbé该问题已超过7岁。那时候,人们不会寻找一个可以高兴的人。那是最初的阶段。请不要滥用那些从网站开始阶段贡献的人 – 2017-07-28 07:58:19
@SagarV我不是“滥用”任何人。这个问题出现在我的“关闭投票”审查队列中。我认为,如果今天某件事不符合我们的质量标准,即使它在发布时符合质量标准,它也应该被删除。但我现在明白为什么它首先得到了提升。 – 2017-07-28 08:03:31