Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #611 from xamarin/dev/api-fix-510
Browse files Browse the repository at this point in the history
GH-510: If there is no main window, then there is no UI thread
  • Loading branch information
mattleibow authored Nov 7, 2018
2 parents 8d0712a + dc5e8b9 commit 9161aa2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Xamarin.Essentials/MainThread/MainThread.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ namespace Xamarin.Essentials
{
public static partial class MainThread
{
static bool PlatformIsMainThread =>
CoreApplication.MainView.CoreWindow?.Dispatcher?.HasThreadAccess ?? false;
static bool PlatformIsMainThread
{
get
{
// if there is no main window, then this is either a service
// or the UI is not yet constructed, so the main thread is the
// current thread
if (CoreApplication.MainView.CoreWindow == null)
return true;

return CoreApplication.MainView.CoreWindow.Dispatcher?.HasThreadAccess ?? false;
}
}

static void PlatformBeginInvokeOnMainThread(Action action)
{
Expand Down

0 comments on commit 9161aa2

Please sign in to comment.