Skip to content

Commit 77e160a

Browse files
KAS1990glennawatson
authored andcommitted
Fix: fatal exception "Element not found" in UWP multiple views apps (#2215)
1 parent f0dbc9c commit 77e160a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ReactiveUI/Platforms/uap/SingleWindowDispatcherScheduler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
1+
// Copyright (c) 2019 .NET Foundation and Contributors. All rights reserved.
22
// Licensed to the .NET Foundation under one or more agreements.
33
// The .NET Foundation licenses this file to you under the MIT license.
44
// See the LICENSE file in the project root for full license information.
55

66
using System;
7+
using System.Linq;
78
using System.Reactive.Concurrency;
89
using System.Reactive.Disposables;
910
using System.Reactive.PlatformServices;
@@ -149,9 +150,9 @@ void RaiseToDispatcher(object sender, object e)
149150

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

154-
if (_dispatcher.HasThreadAccess)
155+
if (_dispatcher == null || _dispatcher.HasThreadAccess)
155156
{
156157
return action(this, state);
157158
}

0 commit comments

Comments
 (0)