From e39ce5557dc975c93fd49142e0359f8af60ef187 Mon Sep 17 00:00:00 2001 From: James Montemagno Date: Fri, 31 May 2019 10:24:54 -0700 Subject: [PATCH] Check for null MainView (#803) --- Xamarin.Essentials/MainThread/MainThread.uwp.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Xamarin.Essentials/MainThread/MainThread.uwp.cs b/Xamarin.Essentials/MainThread/MainThread.uwp.cs index 30170b8ea..2030eacc6 100644 --- a/Xamarin.Essentials/MainThread/MainThread.uwp.cs +++ b/Xamarin.Essentials/MainThread/MainThread.uwp.cs @@ -13,7 +13,7 @@ static bool PlatformIsMainThread // 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) + if (CoreApplication.MainView?.CoreWindow == null) return true; return CoreApplication.MainView.CoreWindow.Dispatcher?.HasThreadAccess ?? false; @@ -22,7 +22,7 @@ static bool PlatformIsMainThread static void PlatformBeginInvokeOnMainThread(Action action) { - var dispatcher = CoreApplication.MainView.CoreWindow?.Dispatcher; + var dispatcher = CoreApplication.MainView?.CoreWindow?.Dispatcher; if (dispatcher == null) throw new InvalidOperationException("Unable to find main thread.");