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



当我尝试在同一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 

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

相关内容

  • 没有找到相关文章

最新更新