From 927ee4626e442decace8e2dcc5719dc0888c60ef Mon Sep 17 00:00:00 2001 From: John Colvin Date: Mon, 14 Feb 2022 14:31:14 -0500 Subject: [PATCH 1/4] Set vs window title to vs name --- .../spark/Modules/Analytics/VolSurface/VolSurfaceWindow.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/spark/Modules/Analytics/VolSurface/VolSurfaceWindow.cs b/src/client/spark/Modules/Analytics/VolSurface/VolSurfaceWindow.cs index 9fa69c408..8e831b958 100644 --- a/src/client/spark/Modules/Analytics/VolSurface/VolSurfaceWindow.cs +++ b/src/client/spark/Modules/Analytics/VolSurface/VolSurfaceWindow.cs @@ -22,7 +22,7 @@ public VolSurfaceWindow( VolSurfaceWindowFactory factory, IBus bus, string vs_name, VolSurfaceWindowSettings startup_data) : - base("Vol Surface", bus, factory, Icons.vol_surface) { + base(vs_name, bus, factory, Icons.vol_surface) { _startup_data = startup_data ?? throw new ArgumentNullException(nameof(startup_data)); this.vs_name = vs_name; _dispose = Disposable.Create(() => Disposable.dispose(ref _vm)); From e020cca9d27c3b26605b5612d7e31fd817358da8 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 15 Feb 2022 12:42:29 -0500 Subject: [PATCH 2/4] fix: Don't await dispatcher op in OnDispatcher notify impl Bugs (fixed): * Crash on shutdown if OptionsView window is open, due to an unhandled TaskAborted exception in the OnDispatcher ext fn --- .../spark/core/GlobalExtensions/GlobalExtensions.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs b/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs index cd4afa871..309f5f5e5 100644 --- a/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs +++ b/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs @@ -295,8 +295,12 @@ namespace System.Reactive.Linq { var dispatcher = Dispatcher.CurrentDispatcher; return Observable.Create(o => { return source.Subscribe(on_next); - async void on_next(T value) { - await dispatcher.check_invoke_async(() => o.OnNext(value), priority); + void on_next(T value) { + if (dispatcher.CheckAccess()) { + o.OnNext(value); + return; + } + dispatcher.InvokeAsync(() => o.OnNext(value), priority); } }); } From 09aeef03a64e3cd105427009dedb40704b3d52c8 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 15 Feb 2022 12:52:33 -0500 Subject: [PATCH 3/4] fix: Use calling thread's Dispatcher in SubscribeOnDispatcher --- .../spark/core/GlobalExtensions/GlobalExtensions.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs b/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs index 309f5f5e5..788dc45b0 100644 --- a/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs +++ b/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs @@ -307,13 +307,23 @@ namespace System.Reactive.Linq { public static IObservable SubscribeOnDispatcher( this IObservable source, + DispatcherPriority priority = DispatcherPriority.Background) => + source.SubscribeOnDispatcher(Dispatcher.CurrentDispatcher, priority); + + public static IObservable SubscribeOnDispatcher( + this IObservable source, + Dispatcher dispatcher, DispatcherPriority priority = DispatcherPriority.Background) { + if (dispatcher is null) { + throw new ArgumentNullException(nameof(dispatcher)); + } + return Observable.Create(o => { object locker = new(); // init sub to a non-null instance, and let 'sub == null' signal // that the subscription has been disposed IDisposable sub = Disposable.empty; - Dispatcher.CurrentDispatcher.InvokeAsync(subscribe, priority); + dispatcher.InvokeAsync(subscribe, priority); return Disposable.Create(dispose); void subscribe() { From 8a17adb49d9c94fac8f291269dd96169a9555eeb Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 15 Feb 2022 12:55:55 -0500 Subject: [PATCH 4/4] refactor: Overload OnDispatcher w/ Dispatcher param By default, this param is assigned Dispatcher.CurrentDispatcher. This follows the overload pattern in SubscribeOnDispatcher --- .../core/GlobalExtensions/GlobalExtensions.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs b/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs index 788dc45b0..f731a39b3 100644 --- a/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs +++ b/src/client/spark/core/GlobalExtensions/GlobalExtensions.cs @@ -284,15 +284,19 @@ namespace System.Collections.Specialized { namespace System.Reactive.Linq { static class SparkObservableExtensions { - // This is placed here to intentionally make ObserveOnDispatcher ambiguous with the one provided by Rx - public static IObservable ObserveOnDispatcher(this IObservable source) { - throw new InvalidOperationException("This method can starve the UI of input messages. Please use OnDispatcher() instead"); - } + public static IObservable OnDispatcher( + this IObservable source, + DispatcherPriority priority = DispatcherPriority.Background) => + source.OnDispatcher(Dispatcher.CurrentDispatcher, priority); public static IObservable OnDispatcher( this IObservable source, + Dispatcher dispatcher, DispatcherPriority priority = DispatcherPriority.Background) { - var dispatcher = Dispatcher.CurrentDispatcher; + if (dispatcher is null) { + throw new ArgumentNullException(nameof(dispatcher)); + } + return Observable.Create(o => { return source.Subscribe(on_next); void on_next(T value) {