Keanu Lorenzo
Keanu Lorenzo

Reputation: 79

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

I have a code that will download a file using WebBrowser.Navigate(DownloadLink) 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 WebBrowser is finished downloading?

Upvotes: 1

Views: 576

Answers (1)

Cee McSharpface
Cee McSharpface

Reputation: 8726

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.

Upvotes: 1

Related Questions