From 7fbaaf9585b15fc492c0eab73ed1603a707a2e09 Mon Sep 17 00:00:00 2001 From: akarnokd Date: Fri, 25 May 2018 14:39:34 +0200 Subject: [PATCH 1/2] 4.x: Have the ControlScheduler do more eager disposed checks --- .../Desktop/Concurrency/ControlScheduler.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/ControlScheduler.cs b/Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/ControlScheduler.cs index 80d8510e80..4479855ddb 100644 --- a/Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/ControlScheduler.cs +++ b/Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/ControlScheduler.cs @@ -52,11 +52,13 @@ public override IDisposable Schedule(TState state, Func { - if (!d.IsDisposed) + if (!_control.IsDisposed && !d.IsDisposed) d.Disposable = action(this, state); })); @@ -94,7 +96,10 @@ public override IDisposable Schedule(TState state, TimeSpan dueTime, Fun { try { - d.Disposable = action(scheduler1, state1); + if (!_control.IsDisposed && !d.IsDisposed) + { + d.Disposable = action(scheduler1, state1); + } } finally { @@ -156,7 +161,10 @@ public IDisposable SchedulePeriodic(TState state, TimeSpan period, Func< timer.Tick += (s, e) => { - state1 = action(state1); + if (!_control.IsDisposed) + { + state1 = action(state1); + } }; timer.Interval = (int)period.TotalMilliseconds; From 3331b76ef1dc156a4d0e3ce77e13fa69baaa20ab Mon Sep 17 00:00:00 2001 From: akarnokd Date: Fri, 25 May 2018 14:57:02 +0200 Subject: [PATCH 2/2] Fix style --- .../Platforms/Desktop/Concurrency/ControlScheduler.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/ControlScheduler.cs b/Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/ControlScheduler.cs index 4479855ddb..0e4830d870 100644 --- a/Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/ControlScheduler.cs +++ b/Rx.NET/Source/src/System.Reactive/Platforms/Desktop/Concurrency/ControlScheduler.cs @@ -52,7 +52,10 @@ public override IDisposable Schedule(TState state, Func