好吧我在Visual Basic中遇到问题,我得到了下载图片的代码. WC.DownloadFileAsync(New Uri("picturelinkhere"), "c:\myfile.jpg") 之后,我有一个灰色下载按钮的代码 Button1.Enabled = False 问题是我想在再次启用
WC.DownloadFileAsync(New Uri("picturelinkhere"), "c:\myfile.jpg")
之后,我有一个灰色下载按钮的代码
Button1.Enabled = False
问题是我想在再次启用Button1之前等待文件下载完成.
我试过用
System.Threading.Thread.Sleep(1000)
但问题在于它使得程序中的进度条非常滞后.
有任何想法吗?
根据 MSDN:To receive notification when the file is available, add an event handler to the DownloadFileCompleted event.
所以,例如,你可以这样做:
AddHandler WC.DownloadFileCompleted, AddressOf DownloadFileCompleted
然后在事件处理程序方法中重新启用按钮,如下所示:
Private Sub DownloadFileCompleted(sender As Object, e As AsyncCompletedEventArgs) Button1.Enabled = True End Sub