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.
///