System.InvalidOperationException was unhandled
Message: An unhandled exception of type 'System.InvalidOperationException' occurred in WindowsBase.dll
Additional information: The calling thread cannot access this object because a different thread owns it.
<KtWpf:KorUserControl x:Class="KtWpf.CEFSharpUtilityMap" xmlns:KtWpf="clr-namespace:KtWpf" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" > <DockPanel> <TextBox DockPanel.Dock="Top">CEFSharp</TextBox> <WebBrowser x:Name="mapBrowser" Source="http://www.google.com" /> </DockPanel></KtWpf:KorUserControl>
<KtWpf:KorUserControl x:Class="KtWpf.CEFSharpUtilityMap" xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" xmlns:KtWpf="clr-namespace:KtWpf" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" > <DockPanel> <TextBox DockPanel.Dock="Top">CEFSharp</TextBox> <cefSharp:ChromiumWebBrowser x:Name="mapBrowser" Address="http://www.google.com" /> </DockPanel></KtWpf:KorUserControl>
I've noticed ChromiumWebBrowser inside WPF makes for a lot pickier experience about which thread created what.For example, I hooked up an event to the browser's FrameLoadEnd. With the MS control, I could do this:if (WindowState == WindowState.Minimized || Visibility != Visibility.Visible)With the CefSharp control, this complains in exactly the manner you describe. You can't even ask what the WindowState is, never mind set it.I put the event handler in a separate method and called it this way:Dispatcher.Invoke(() => FrameLoadEndHandler(sender, nowVisible));
orApplication.Current.Dispatcher.Invoke(() => FrameLoadEndHandler(sender, nowVisible));I don't know if that at all helps with the issue you have there, but just to let you know that events in the CefSharp stuff are not necessarily the same as WPF's main UI thread and that can trigger such warnings.-- Ritchie Annand
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Cef.Initialize();
...
}
protected override void OnExit(ExitEventArgs e)
{
Cef.Shutdown();
base.OnExit(e);
}