Welcome Guest Search | Active Topics | Sign In | Register

Webview file download occasionally freezing Options
Louis
Posted: Tuesday, January 14, 2020 11:34:51 AM
Rank: Advanced Member
Groups: Member

Joined: 6/20/2016
Posts: 32
I am downloading files using webView1.Download(source, destination), but occasionally it completely hangs up.

Is there any kind of timeout mechanism that I can use, or a way to cancel the download programmatically? I didn't see anything obvious in the documentation.

Thanks for the assistance
eo_support
Posted: Tuesday, January 14, 2020 7:25:41 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

This usually is caused by some third party firewall/security software that filters the network traffic. There is no built-in timeout mechanism but you can setup a timer to check the DownloadItem's CurrentSpeed property or TotalBytes property:

https://www.essentialobjects.com/doc/eo.webbrowser.downloaditem.currentspeed.aspx
https://www.essentialobjects.com/doc/eo.webbrowser.downloaditem.totalbytes.aspx

If you see CurrentSpeed reduces to 0 for a while or TotalBytes not changing for a while, then you can call DownloadItem.Cancel to canel it:

https://www.essentialobjects.com/doc/eo.webbrowser.downloaditem.cancel.aspx

Thanks!
Louis
Posted: Wednesday, January 15, 2020 11:11:34 AM
Rank: Advanced Member
Groups: Member

Joined: 6/20/2016
Posts: 32
Thanks a lot, that sounds like a good solution, but unfortunately I cannot get it to work.

I've added the following code to test:

AddHandler webView1.DownloadUpdated, New EO.WebBrowser.DownloadEventHandler(AddressOf WebView1_DownloadUpdated)
AddHandler webView1.BeforeDownload, New EO.WebBrowser.BeforeDownloadHandler(AddressOf WebView1_BeforeDownload)

Private Sub WebView1_BeforeDownload(sender As Object, e As DownloadEventArgs)

debug.print(e.Item.TotalBytes)

End Sub

Private Sub WebView1_DownloadUpdated(sender As Object, e As DownloadEventArgs)

debug.print(e.Item.TotalBytes)

End Sub


However, when I call webView1.Download(source, destination) neither of those two handlers ever get triggered.

What am I doing wrong?
eo_support
Posted: Friday, January 17, 2020 3:15:55 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

This does seems to be an issue. We have looked into this and the root of the problem is the code in Download method actually uses a secondary WebView to process the download in order to avoid "touching" the WebView on which Download method is called. The basic logic inside Download method is as follow:

1. Create a new WebView;
2. Handle the WebView's ShouldForceDownload to always force download. This is needed so that the WebView can download instead of display a HTML file;
3. Handle other Download related event to collect result data;
4. Call WebView.LoadUrl to load the Url;
5. Wait for DownloadComplete event is fired (or an error occurs);
6. Destroy the WebView;

You can try to duplicate this logic in your own code and add additional timeout code. You do not have to create a second WebView. If you have any additional question while trying to implement this logic please feel free to ask.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.