2013-03-20 153 views
2

我想知道是否有辦法讓我的應用程序等待\暫停直到文件被合理下載。等待文件下載vb.net

該文件dowloaded尤斯如下因素代碼...

'Downloads file from URL... 
Dim mywebclient As New System.Net.WebClient() 
mywebclient.DownloadFile(UPDATEURL & "/UPDATE.exe", "C:\mylocalfolder\UPDATE.exe") 

林尤斯VB.net對於那些想知道誰...

回答

1

你可以在表單的Enabled屬性設置爲false當您開始下載並使用WebClientDownloadComplete事件將Enabled屬性設置爲True時。不知道等待/暫停可能意味着什麼,因爲該方法不是異步的。

'Downloads file from URL... 
Try 
    Me.Enabled = False 
    Dim mywebclient As New System.Net.WebClient() 
    Addhandler mywebclient.DownloadFileComplete, AddressOf wc_downloadComplete 
    mywebclient.DownloadFile(UPDATEURL & "/UPDATE.exe", "C:\mylocalfolder\UPDATE.exe") 
Catch 
    'in case something fails 
    Me.Enabled = True 
End Try 


Private Sub wc_downloadComplete(sender As Object, e As AsyncCompletedEventArgs) 
    Me.Enabled = True 
End Sub