對於我的應用程序,我想向用戶顯示網絡帶寬。所以,延遲下載將被用戶知道..是否有可能向他們展示?在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. 使用Java測量內部網絡速度/帶寬
- 5. 如何可靠地測量進程使用的網絡帶寬
- 6. 爲什麼網絡帶寬以MHz爲單位進行測量?
- 7. Java:測量特定代碼段的網絡帶寬
- 8. 控制網絡帶寬
- 9. 如何測量互聯網帶寬
- 10. C插槽來測量帶寬
- 11. 檢測C#中的網絡連接速度和帶寬使用情況
- 12. 使用PHP測量帶寬
- 13. 測量WCF網絡流量
- 14. 網絡丟包延遲帶寬模擬
- 15. 使用.NET計算網絡帶寬
- 16. 移動網絡代和帶寬
- 17. Azure雲服務網絡帶寬
- 18. 虛擬盒限制帶寬網絡
- 19. 限制java進程的網絡帶寬
- 20. 網絡帶寬評估工具
- 21. 利他網絡連接帶寬估計
- 22. 連接到Android外殼的寬帶網絡和WiFi網絡
- 23. 在c中測量網絡性能工具#
- 24. 無網絡測量距離
- 25. 測量網絡時間
- 26. 如何驗證網絡應用程序中的網絡帶寬問題
- 27. 如何測量SSH隧道的帶寬?
- 28. 在TableLayout中測量列寬
- 29. 使用Indy測量網絡流量
- 30. 如何測量網絡流量?
@RomanoZumbé該問題已超過7歲。那時候,人們不會尋找一個可以高興的人。那是最初的階段。請不要濫用那些從網站開始階段貢獻的人 – 2017-07-28 07:58:19
@SagarV我不是「濫用」任何人。這個問題出現在我的「關閉投票」審查隊列中。我認爲,如果今天某件事不符合我們的質量標準,即使它在發佈時符合質量標準,它也應該被刪除。但我現在明白爲什麼它首先得到了提升。 – 2017-07-28 08:03:31