我有以下代码。按钮 1 工作正常并在下载完全完成后启动。然而,按钮 2 正试图在完成 50% 左右时启动。有人知道为什么吗?
Imports System.Net
Imports System.Threading
Imports System.ComponentModel
Public Class Form1
' Occurs when an asynchronous file download operation completes.
Private Sub _DownloadFileCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
' File download completed
Button1.Text = "Launching..."
Shell("C:\war.exe")
End Sub
Private Sub _DownloadFileCompleted2(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
' File download completed
Button2.Text = "Launching..."
Shell("C:\war.exe")
End Sub
' Occurs when an asynchronous download operation successfully transfers some or all of the data.
Private Sub _DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
' Update progress bar
ProgressBar1.Value = e.ProgressPercentage
End Sub
' download button click event
Private Sub download_button_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
' Disable download button to avoid clicking again while downloading the file
Button1.Text = "Downloading Updates"
Button2.Visible = False
' Downloads, to a local file, the resource with the specified URI.
' This method does not block the calling thread.
Dim _WebClient As New WebClient()
AddHandler _WebClient.DownloadFileCompleted, AddressOf _DownloadFileCompleted
AddHandler _WebClient.DownloadProgressChanged, AddressOf _DownloadProgressChanged
_WebClient.DownloadFileAsync(New Uri("http://www.url.com"), "C:\prog.exe")
End Sub
Private Sub download_button_Click2(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
' Disable download button to avoid clicking again while downloading the file
Button2.Text = "Downloading Updates"
Button1.Visible = False
' Downloads, to a local file, the resource with the specified URI.
' This method does not block the calling thread.
Dim _WebClient2 As New WebClient()
AddHandler _WebClient2.DownloadFileCompleted, AddressOf _DownloadFileCompleted2
AddHandler _WebClient2.DownloadProgressChanged, AddressOf _DownloadProgressChanged
_WebClient2.DownloadFileAsync(New Uri("http://www.url.com"), "C:\prog.exe")
End Sub
End Class
提前致谢