We have a WPF application and loading a web page over a slow connection e.g. VPN might take longer.
When closing the view while loading I get a crash
Version: EO.Base, Version=20.3.34.0
This WebView either has already been destroyed or is being destroyed.
EO.Base.Runtime.itno(System.Object, System.Exception, Boolean)
EO.WebBrowser.WebView.nwgo(System.Exception, Boolean)
EO.WebBrowser.WebView.nwct(Boolean)
EO.WebBrowser.WebView.nwgw(EO.WebBrowser.WaitableTask, Boolean)
EO.WebBrowser.WaitableTask.ippz(EO.WebBrowser.WebView, Boolean)
EO.WebBrowser.NavigationTask..ctor(EO.Internal.ietr, EO.Internal.rhuo, System.String, System.String, EO.WebBrowser.Request,
EO.WebBrowser.WebView+nhec.nwdc(System.String, System.String, Boolean)
EO.WebBrowser.WebView.ywwe()
EO.WebBrowser.WebView.mmom()
EO.WebBrowser.WebView.nwco(Boolean)
EO.WebBrowser.WebView.Destroy()
System.ComponentModel.Component.Dispose()
The original code looked like this.
Code: C#
Load()
EO.WebBrowser.Request request = new EO.WebBrowser.Request(webContext.TargetURI.AbsoluteUri);
request.PostData.SetRawData(webContext.PostData);
request.Method = "POST";
this.webBrowser.LoadRequest(request);
protected virtual void Dispose(bool disposing)
{
if (this.webBrowser != null)
{
this.webBrowser.Dispose();
Investigating I found out that this only happens if the page is not loaded fully
Code: C#
protected virtual void Dispose(bool disposing)
{
if (this.webBrowser != null)
{
//In case async loading
int nrOfRetries = 10;
while (this.webBrowser.IsLoading && nrOfRetries > 0)
{
Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Waiting for load to be complete: retries left {0}", nrOfRetries));
this.webBrowser.StopLoad();
Thread.Sleep(1000);
nrOfRetries--;
}
if (this.webBrowser.IsCreated && this.webBrowser.IsReady)
{
this.webBrowser.Dispose();
StopLoad() does not cancel the load operation as I would have expected.
It stops loading, but then IsLoading will be always true, (I tried with 1000 :))
What is the correct sequence to shut down a view with a webcontrol while the page has not finished loading