Home > Net >  Unable to trigger DownloadDataCompleted
Unable to trigger DownloadDataCompleted

Time:09-19

Dim myWebClient As WebClient
Private Sub Form1_Load (sender As Object, As EventArgs e) Handles MyBase. Load
MyWebClient=New WebClient
AddHandler myWebClient DownloadProgressChanged, AddressOf ShowDownProgress 'capture download progress change events,
AddHandler myWebClient DownloadDataCompleted, AddressOf DownloadDataCompleted
DownLoadFiles ()
End Sub
Private Sub DownLoadFiles ()
MyWebClient. DownloadFileAsync (New Uri ( url), "1. Bat")
End Sub

After to the file download properly, but the following code will not be able to trigger, excuse me, is there something wrong

Sub DownloadDataCompleted (ByVal sender As Object, ByVal e As System.Com ponentModel. AsyncCompletedEventArgs)
If MessageBox. Show (" open just download the program ", "prompt", MessageBoxButtons. YesNo)=DialogResult. Yes Then

System. Diagnostics. Process. The Start (" 1. Bat ") 'Start just download the program
End the if
end sub

CodePudding user response:

This is asynchronous download, you want to write a callback function

CodePudding user response:

Didn't do it, whether you can compare the size and the size of the already downloaded

CodePudding user response:

Asynchronous download file, when the download is complete, should handle DownloadFileCompleted events, rather than DownloadDataCompleted events

CodePudding user response:

Private Sub DownLoadFiles ()
MyWebClient=New WebClient
AddHandler WebClient DownloadProgressChanged, New DownloadProgressChangedEventHandler (AddressOf ShowDownProgress)
AddHandler WebClient DownloadFileCompleted, New AsyncCompletedEventHandler (AddressOf DownloadDataCompl)
MyWebClient. DownloadFileAsync (New Uri (url omitted), "1. Bat")
End Sub

To try it like this, with not much
  • Related