Skip to content

Commit

Permalink
Check for null MainView (xamarin#803)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno authored and Schilli, Niklas committed Aug 28, 2019
1 parent c7fa246 commit e39ce55
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Xamarin.Essentials/MainThread/MainThread.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.");
Expand Down

0 comments on commit e39ce55

Please sign in to comment.