Skip to content

Commit 2811858

Browse files
committed
IsExecuting should always be on the UI thread. Fixes #373
1 parent 10db96f commit 2811858

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ReactiveUI/ReactiveCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ public ReactiveCommand(IObservable<bool> canExecute, bool allowsConcurrentExecut
4343

4444
ThrownExceptions = exceptions = new ScheduledSubject<Exception>(defaultScheduler, RxApp.DefaultExceptionHandler);
4545

46-
IsExecuting = inflight
46+
var isExecuting = inflight
4747
.Scan(0, (acc, x) => acc + (x ? 1 : -1))
4848
.Select(x => x > 0)
4949
.Publish(false)
5050
.PermaRef()
5151
.DistinctUntilChanged();
5252

53-
var isBusy = allowsConcurrentExecution ? Observable.Return(false) : IsExecuting;
53+
IsExecuting = isExecuting.ObserveOn(defaultScheduler);
54+
55+
var isBusy = allowsConcurrentExecution ? Observable.Return(false) : isExecuting;
5456
var canExecuteAndNotBusy = Observable.CombineLatest(canExecute, isBusy, (ce, b) => ce && !b);
5557

5658
var canExecuteObs = canExecuteAndNotBusy

0 commit comments

Comments
 (0)