Keanu Lorenzo Keanu Lorenzo - 5 months ago 34 Question

How to know if WebBrowser is finished downloading the file? Visual Basic

I have a code that will download a file using

and it works fine. But I want my application to automatically exit itself after the download is finished. And I don't know how to do it. So is there any way on how to know if
is finished downloading?


The WebBrowser component is a wrapper around Internet Explorer, which downloads asynchronously. Now we could come up with various hacks that would answer your question and maybe solve the problem, but I strongly suggest to use a different approach to download a file, at least if there's no other reason for you to keep WebBrowser in your application:

WebClient.DownloadFile "This method blocks while downloading the resource".

Public Sub Download(address As String, localfile As String)
    Using client As New System.Net.WebClient()
        client.DownloadFile("some url", "local file path to save")
    End Using
End Sub

You also can use WebClient.DownloadFileAsync which doesn't block UI.