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

Check for null MainView on UWP #803

Merged
merged 2 commits into from
May 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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