本文介绍了如何检测平均下载速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我想制作一个Speedtest,我正在下载一个100MB的文件(测试平均下载速度是不是太多了?)。
我得到了一个巨大的数字,我不能计算平均下载速度......
Offtopic:还有办法计算平均上传速度吗?
我尝试过:
So I want to make an Speedtest alike, I am downloading an 100MB file (is it too much to test average download speed?).
I am getting an huge number and I can't calculate the average download speed like that...
Offtopic: Is there also a way to calculate the average upload speed?
What I have tried:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Downloading Then Exit Sub
Downloading = True
Dim wc As New WebClient
AddHandler wc.DownloadProgressChanged, AddressOf wc_ProgressChanged
AddHandler wc.DownloadFileCompleted, AddressOf wc_DownloadDone
wc.DownloadFileAsync(New Uri("http://speedtest.ftp.otenet.gr/files/test100Mb.db"), tmp, Stopwatch.StartNew)
End Sub
Private Sub wc_DownloadDone(sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs)
Downloading = False
End Sub
Private Sub wc_ProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs)
Me.Label2.Text = (e.BytesReceived / (DirectCast(e.UserState, Stopwatch).ElapsedMilliseconds / 1000.0#)).ToString("#")
End Sub
推荐答案
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If Downloading Then Exit Sub
Downloading = True
Dim wc As New WebClient
AddHandler wc.DownloadProgressChanged, AddressOf wc_ProgressChanged
AddHandler wc.DownloadFileCompleted, AddressOf wc_DownloadDone
wc.DownloadFileAsync(New Uri("http://speedtest.ftp.otenet.gr/files/test1Gb.db"), tmp, Stopwatch.StartNew)
End Sub
Private Sub wc_DownloadDone(sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs)
Downloading = False
End Sub
Private Sub wc_ProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs)
Label33.Text = (e.BytesReceived / (DirectCast(e.UserState, Stopwatch).ElapsedMilliseconds / 1000.0#) / (1024 * 1024) * 8).ToString("#") & " MB"
End Sub
这篇关于如何检测平均下载速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!