Skip to content
Permalink
Browse files

Fix: fatal exception "Element not found" in UWP multiple views apps (#…

  • Loading branch information...
KAS1990 authored and glennawatson committed Oct 15, 2019
1 parent f0dbc9c commit 77e160a639f7337b507110478f9ecacda6c5576f
Showing with 4 additions and 3 deletions.
  1. +4 −3 src/ReactiveUI/Platforms/uap/SingleWindowDispatcherScheduler.cs
@@ -1,9 +1,10 @@
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.PlatformServices;
@@ -149,9 +150,9 @@ void RaiseToDispatcher(object sender, object e)

private IDisposable ScheduleOnDispatcherNow<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
{
Interlocked.CompareExchange(ref _dispatcher, CoreApplication.Views[0].Dispatcher, null);
Interlocked.CompareExchange(ref _dispatcher, CoreApplication.Views.FirstOrDefault()?.Dispatcher, null);

if (_dispatcher.HasThreadAccess)
if (_dispatcher == null || _dispatcher.HasThreadAccess)
{
return action(this, state);
}

0 comments on commit 77e160a

Please sign in to comment.
You can’t perform that action at this time.