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
|
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.aspxhttps://www.essentialobjects.com/doc/eo.webbrowser.downloaditem.totalbytes.aspxIf 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.aspxThanks!
|
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?
|
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!
|