From 3e32e0e306fa44bf9a8df0d18e729d4e75888bce Mon Sep 17 00:00:00 2001 From: amaitland Date: Fri, 14 Oct 2016 11:57:49 +1000 Subject: [PATCH] WPF - Update Custom cursor in a sync fashion resolves #606 --- CefSharp.Wpf/ChromiumWebBrowser.cs | 41 +++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 0de594736..a91707d6a 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -646,10 +646,26 @@ namespace CefSharp.Wpf /// The type. void IRenderWebBrowser.SetCursor(IntPtr handle, CefCursorType type) { - UiThreadRunAsync(() => + //Custom cursors are handled differently, for now keep standard ones executing + //in an async fashion + if(type == CefCursorType.Custom) { - Cursor = CursorInteropHelper.Create(new SafeFileHandle(handle, ownsHandle: false)); - }); + //When using a custom it appears we need to update the cursor in a sync fashion + //Likely the underlying handle/buffer is being released before the cursor + // is created when executed in an async fashion. Doesn't seem to be a problem + //for build in cursor types + UiThreadRunSync(() => + { + Cursor = CursorInteropHelper.Create(new SafeFileHandle(handle, ownsHandle: false)); + }); + } + else + { + UiThreadRunAsync(() => + { + Cursor = CursorInteropHelper.Create(new SafeFileHandle(handle, ownsHandle: false)); + }); + } } /// @@ -1423,7 +1439,7 @@ namespace CefSharp.Wpf } /// - /// UIs the thread run asynchronous. + /// Runs the specific Action on the Dispatcher in an async fashion /// /// The action. /// The priority. @@ -1439,6 +1455,23 @@ namespace CefSharp.Wpf } } + /// + /// Runs the specific Action on the Dispatcher in an sync fashion + /// + /// The action. + /// The priority. + private void UiThreadRunSync(Action action, DispatcherPriority priority = DispatcherPriority.DataBind) + { + if (Dispatcher.CheckAccess()) + { + action(); + } + else if (!Dispatcher.HasShutdownStarted) + { + Dispatcher.Invoke(action, priority); + } + } + /// /// Handles the event. ///