合并多个文件的WebClient AsyncCompleted事件

问题描述

我有一个Windows窗体,用户可以通过该窗体选择他们要下载的多个文件。下载文件后,将对其进行进一步处理。我正在使用AsyncCompletedEventArgs事件来跟踪每次下载的进度。

使用以下功能下载每个选定文件

Public Function DownloadFileOnline(FileName As String)
    Try
        fileReader = New WebClient()
        Dim Address As String
                
        Address = getURL(FileName)
        If (Not System.IO.Directory.Exists(Globals.LocalPath)) Then
            System.IO.Directory.CreateDirectory(Globals.LocalPath)
        End If
        If Not (System.IO.File.Exists(Globals.LocalPath + FileName)) Then
            AddHandler fileReader.DownloadFileCompleted,AddressOf download_complete
            AddHandler fileReader.DownloadProgressChanged,AddressOf Download_ProgressChanged
            fileReader.QueryString.Add("fileName",FileName)
            fileReader.DownloadFileAsync(New Uri(Address),Globals.LocalPath + FileName)
        End If
    Catch ex As HttpListenerException
        CSMessageBox.ShowError("Error accessing the Library",ex)
        LogHelper.WriteLog("Error accessing the Library" + ex.Message,LogHelper.LogLevels.Error)
    Catch ex As Exception
        CSMessageBox.ShowError("Error accessing the Library",LogHelper.LogLevels.Error)
    End Try
End Function

我可以使用以下功能分别获取每个文件的下载完成事件:

Private Sub download_complete(ByVal sender As Object,ByVal e As AsyncCompletedEventArgs)
    RaiseEvent DownloadDone(sender,e)
    RemoveHandler fileReader.DownloadFileCompleted,AddressOf download_complete
    RemoveHandler fileReader.DownloadProgressChanged,AddressOf Download_ProgressChanged
End Sub

一旦下载了所有文件,我计划对所有文件一起执行一个功能。当所有选定文件下载完毕后,有什么方法可以引发事件吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)