Skip to content

Commit

Permalink
fix: Handle UnoXamlHostBase end of app lifecycle gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Feb 27, 2023
1 parent d3942bb commit 6a3b198
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/Uno.UI.XamlHost.Skia.Wpf/UnoXamlHostBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,30 @@ static UnoXamlHostBase()
{
//TODO: These lines should be set in a different location, possibly in a more general way (for multi-window support) https://github.com/unoplatform/uno/issues/8978
Windows.UI.Core.CoreDispatcher.DispatchOverride = d =>
global::System.Windows.Application.Current.Dispatcher.BeginInvoke(d);
Windows.UI.Core.CoreDispatcher.HasThreadAccessOverride =
global::System.Windows.Application.Current.Dispatcher.CheckAccess;
{
if (global::System.Windows.Application.Current is { } app)
{
app.Dispatcher.BeginInvoke(d);
}
else
{
// The Application instance may not yet have been initialized, or may have already been disposed.
}
};

Windows.UI.Core.CoreDispatcher.HasThreadAccessOverride = () =>
{
if (global::System.Windows.Application.Current is { } app)
{
return app.Dispatcher.CheckAccess();
}
else
{
// The Application instance may not yet have been initialized, or may have already been disposed.
return false;
}
};

if (MetadataProviderDiscovery.MetadataProviderFactory is null)
{
MetadataProviderDiscovery.MetadataProviderFactory = type =>
Expand Down

0 comments on commit 6a3b198

Please sign in to comment.