如何在C#中获得网速? [英] How to get internet speed in C#?
本文介绍了如何在C#中获得网速?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在c#.Net上获得网速?
请知道是否有人知道。在此先感谢...
解决方案
这里有两篇文章详细描述了如何改进ASP.NET应用程序(用C#创建的Web应用程序):
http://www.realsoftwaredevelopment.com/20-tips- to-improve-aspnet-application-performance / [ ^ ]
http:// www。 sitepoint.com/aspnet-performance-tips/ [ ^ ]
你可以这样做。
这个例子下载一个网页,测量所需的时间
然后计算每秒的字节速度。
Stopwat ch stopwatch = new 秒表();
stopwatch.Reset();
stopwatch.Start();
WebClient webClient = new WebClient();
byte [] bytes = webClient.DownloadData( http://www.codeproject.com跨度>);
秒表.Stop();
double seconds = stopwatch.Elapsed.TotalSeconds;
double speed = bytes.Count()/ seconds;
MessageBox.Show( string .Format( 你的速度:每秒{0}字节。,速度));
参考:在C#中检测网络连接速度和带宽使用情况 [ ^
Hi,
How to get Internet speed in c#.Net?
Please le ne know if anybody knows. Thanks in advance...
解决方案
Here are two articles that describe in details how to improve the ASP.NET application (web application created in C#):
http://www.realsoftwaredevelopment.com/20-tips-to-improve-aspnet-application-performance/[^]
http://www.sitepoint.com/aspnet-performance-tips/[^]
You could do it like this.
This example downloads a web page, measures the time needed
and then calculates the speed in bytes per seconds.
Stopwatch stopwatch = new Stopwatch(); stopwatch.Reset(); stopwatch.Start(); WebClient webClient = new WebClient(); byte[] bytes = webClient.DownloadData("http://www.codeproject.com"); stopwatch.Stop(); double seconds = stopwatch.Elapsed.TotalSeconds; double speed = bytes.Count() / seconds; MessageBox.Show(string.Format("Your speed: {0} bytes per second.", speed));
Refer: Detecting network connection speed and bandwidth usage in C#[^]
这篇关于如何在C#中获得网速?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文