Welcome Guest Search | Active Topics | Sign In | Register

Problem with Destroy error message Options
DylanT
Posted: Tuesday, July 10, 2018 11:41:45 PM
Rank: Member
Groups: Member

Joined: 6/5/2018
Posts: 14
We've been getting this error a lot lately, and it causes our application to halt. We can't seem to trap it or prevent it:
System.Exception
HResult=0x80131500
Message=Destroy must be called from the same thread the WebView is created.
Source=EO.WebBrowser
StackTrace:
at EO.WebBrowser.WebView.g(Boolean A_0)
at EO.Wpf.WebViewHost.a.a(Boolean A_0)
at System.Windows.Interop.HwndHost.Finalize()

Previously we were using version 17.3.13.0 and never got this error.

This started occurring after we moved to 18.1.75.0

Is there a way to catch this exception or prevent it being thrown? It's a major issue for us.

Edited to Add:
Obviously, we are currently creating and destroying the WebView on the same thread. Or at least we think we are! We've never had any trouble before with it.

Edited to also add:
We have worked out a workaround for the moment, but in so doing we may have discovered a useful way for you to reproduce this issue.

Our situation is that we have a WPF application with a TabControl on it. The TabControl is set up with a webview thus:

Code: C#
// this is all inside a class
        private WebView mActiveView;
        private bool _loadImages = false;
        private bool _enableJavaScript = true;

        private void AddBrowserTab(WebView poNewWebView)
        {
            var loNewTab = new TabItem {Header = "New"};
            tabBrowser.Items.Add(loNewTab);

            var loWebControl = new EO.Wpf.WebControl {WebView = poNewWebView};

            mActiveView = poNewWebView;
            mActiveView.SetOptions(new BrowserOptions { LoadImages = _loadImages, AllowJavaScript = _enableJavaScript });
            mActiveView.BeforeDownload += wb_BeforeDownload;
            // snipped various event handlers
            mActiveView.ObjectForScripting = new BrowserListener(ActiveSession);
            loNewTab.Content = loWebControl;

            tabBrowser.SelectedIndex = tabBrowser.Items.Count - 1;
        }


Then, when _loadImages or _enableJavascript is changed, we had other code like this. I have commented on one line, if we remove this line the issue goes away, but the tabcontrol still has the tab on it, just empty. It seems that remvoing the tabcontrol EVEN AFTER Destroying the WebView, throws the exception about about Destroying something on another thread. Our assumption was that the WebView was already destroyed, but apparently not:

Code: C#
public void SetOptions(bool loadImages, bool allowJavaScript)
        {
            if (loadImages == _loadImages && allowJavaScript == _enableJavaScript) return; // Already set correctly

            _loadImages = loadImages;
            _enableJavaScript = allowJavaScript;

            try
            {
                    mActiveView?.Destroy();
                    tabBrowser.Items.Remove(tabBrowser.Items[tabBrowser.Items.Count - 1]); // If we remove this line, then everything works
                    AddBrowserTab(GetNewWebViewWithPreloadedJavascript());
            }
            catch (Exception ex)
            {
                // Log stuff.
            }
        }

eo_support
Posted: Wednesday, July 11, 2018 6:02:45 PM
Rank: Administration
Groups: Administration

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

Usually you would receive this message when you call Destroy from another thread, which does not seem to be the case based on the information you provided. It appears to be a reentering issue. Can you try to isolate the problem into a test project and then send the test project to us? See here for more information on how to send test project to us:

https://www.essentialobjects.com/forum/test_project.aspx

Once we have that we will try to run it here and see what we can find.

Thanks!
DylanT
Posted: Wednesday, July 11, 2018 8:39:44 PM
Rank: Member
Groups: Member

Joined: 6/5/2018
Posts: 14
OK I have sent off a test project reproducing the issue.
eo_support
Posted: Thursday, July 12, 2018 2:49:09 PM
Rank: Administration
Groups: Administration

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

We have looked into your test project and confirmed this to be a bug. The problem is triggered by the WebControl being disposed by the garbage collector (thus from a different thread). In order to avoid this problem, you can call the WebControl's Dispose method explicitly from your code when your window closes. We are also changing the code on our end so that the Destroy call will be automatically rerouted to the main UI thread in such scenario.

Thanks!
DylanT
Posted: Thursday, July 12, 2018 6:58:41 PM
Rank: Member
Groups: Member

Joined: 6/5/2018
Posts: 14
Awesome. Glad to have helped identify another fixable bug! And thankyou for the workaround too.
eo_support
Posted: Thursday, July 12, 2018 10:01:49 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
You are very welcome. Please feel free to let us know if there is anything else.


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.