问题描述
Public WithEvents mclient As New WebClient
Private Sub Download()
Label2.Text = "I am downloading"
Label2.Refresh()
Dim filepath As String = (path+filename+".mp3")
mclient.Encoding = Encoding.UTF8
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
mclient.Headers.Add(HttpRequestHeader.UserAgent,"")
mclient.DownloadFileAsync(New Uri(link),filepath)
End Sub
正在下载:
Private Sub mClient_DownloadProgressChanged(sender As Object,e As DownloadProgressChangedEventArgs) Handles mclient.DownloadProgressChanged
ProgressBar1.Value = e.Progresspercentage
Label1.Text = (Val(e.BytesReceived) / Val(e.TotalBytesToReceive)).ToString("0.00") & "MB Downloaded"
Label2.Text = "Downloading"
Label2.Refresh()
End Sub
要知道下载何时完成,我正在使用:
Private Sub mClient_DownloadFileCompleted(sender As Object,e As AsyncCompletedEventArgs) Handles mclient.DownloadFileCompleted
Label2.Text = "Download completed"
Label2.Refresh()
End Sub
这段代码工作了一段时间,但是今天,我重新打开了项目,运行了它,但是形式有点冻结/解冻。这很奇怪,因为下载和事件都是异步的。 如果下载是异步的,为什么会这样呢? 谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)