未调用 DownloadFileCompleted 事件
DownloadFileCompleted event not being called
我正在尝试从服务器下载文件,但未调用 "DownloadFileCompleted" 事件。
有人知道为什么吗?
来源:
Public Event DownloadFileCompleted As AsyncCompletedEventHandler
Public Sub DownloadCompleted(sender As Object, e As AsyncCompletedEventArgs)
MsgBox("Downloaded")
End Sub
Private Function DLOAD()
Try
Dim WebClientT As New System.Net.WebClient()
AddHandler WebClientT.DownloadFileCompleted, AddressOf DownloadFileCompletedD
ByteArray = WebClientT.DownloadData("https://ip/file.filetype")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
该事件仅在您使用 "DownloadFileAsync" 时调用,因为您正在同步下载,线程将等待下载所有字节而不调用该事件。那么你不需要这个事件。完整下载将始终低于 DownloadData。
如果调用此方法使用
AddHandler WebClientT.DownloadDataCompleted, AddressOf DownloadCompleted
WebClientT.DownloadDataAsync(uri)
更多信息:
我正在尝试从服务器下载文件,但未调用 "DownloadFileCompleted" 事件。 有人知道为什么吗?
来源:
Public Event DownloadFileCompleted As AsyncCompletedEventHandler
Public Sub DownloadCompleted(sender As Object, e As AsyncCompletedEventArgs)
MsgBox("Downloaded")
End Sub
Private Function DLOAD()
Try
Dim WebClientT As New System.Net.WebClient()
AddHandler WebClientT.DownloadFileCompleted, AddressOf DownloadFileCompletedD
ByteArray = WebClientT.DownloadData("https://ip/file.filetype")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
该事件仅在您使用 "DownloadFileAsync" 时调用,因为您正在同步下载,线程将等待下载所有字节而不调用该事件。那么你不需要这个事件。完整下载将始终低于 DownloadData。
如果调用此方法使用
AddHandler WebClientT.DownloadDataCompleted, AddressOf DownloadCompleted
WebClientT.DownloadDataAsync(uri)
更多信息: