使用 DotNetBrowser 在同一个子目录中下载 2 个以上的文件

Download more than 2 files in the same sub using DotNetBrowser

当我尝试在同一个 Sub 中下载 2 个或更多项目时,DotNetBrowser 只下载最后一个。 我应该怎么做才能下载示例中的两个项目?

Sub test()
    _browserview = CType(Me.PanelBrowser.Controls("browsername"), WinFormsBrowserView)
    _browserview.Browser.LoadURL("http://www.7-zip.org/a/7z1604.exe")
    _browserview.Browser.LoadURL("http://www.7-zip.org/a/7z1604-src.7z")
End Sub

这是一个简短的示例,演示了可用于下载多个文件的方法:

Imports System.Threading
Imports DotNetBrowser

Module Module1

    Sub Main()
        Dim browser As Browser
        browser = BrowserFactory.Create()
        browser.DownloadHandler = New SampleDownloadHandler
        DownloadFile(browser, "http://www.7-zip.org/a/7z1604.exe")
        DownloadFile(browser, "http://www.7-zip.org/a/7z1604-src.7z")
        Console.In.ReadLine()
        browser.Dispose()
    End Sub

    Class SampleDownloadHandler
        Implements DownloadHandler

        Public Event AllowDownloadCalled(download As DownloadItem)

        Public Function AllowDownload(download As DownloadItem) As Boolean Implements DownloadHandler.AllowDownload
            AddHandler download.DownloadEvent, Sub(s, e)
                                                   If e.Item.Completed Then
                                                       Console.WriteLine("Downloaded: " + e.Item.DestinationFile)
                                                   End If
                                               End Sub

            Console.WriteLine("Download allowed: " + download.URL)
            RaiseEvent AllowDownloadCalled(download)
            Return True
        End Function
    End Class

    Private Sub DownloadFile(browser As Browser, url As String)
        Dim downloadHandler As SampleDownloadHandler
        downloadHandler = browser.DownloadHandler

        Dim downloadEvent As New ManualResetEvent(False)
        Dim allowDownloadEvent As New SampleDownloadHandler.AllowDownloadCalledEventHandler(Sub(d As DownloadItem) downloadEvent.Set())

        AddHandler downloadHandler.AllowDownloadCalled, allowDownloadEvent
        browser.LoadURL(url)
        downloadEvent.WaitOne()
        RemoveHandler downloadHandler.AllowDownloadCalled, allowDownloadEvent
    End Sub
End Module 

可以通过以下 link 找到演示如何处理这种情况的完整示例: https://dotnetbrowser.support.teamdev.com/support/solutions/articles/9000110831-downloading-several-files