diff --git a/Wabbajack.Common/Extensions/RxExt.cs b/Wabbajack.Common/Extensions/RxExt.cs index 0a1b643e..e0ad02ce 100644 --- a/Wabbajack.Common/Extensions/RxExt.cs +++ b/Wabbajack.Common/Extensions/RxExt.cs @@ -88,7 +88,7 @@ namespace Wabbajack /// Inspiration: /// http://reactivex.io/documentation/operators/debounce.html /// https://stackoverflow.com/questions/20034476/how-can-i-use-reactive-extensions-to-throttle-events-using-a-max-window-size - public static IObservable Debounce(this IObservable source, TimeSpan interval, IScheduler scheduler = null) + public static IObservable Debounce(this IObservable source, TimeSpan interval, IScheduler scheduler) { scheduler = scheduler ?? Scheduler.Default; return Observable.Create(o => @@ -209,15 +209,6 @@ namespace Wabbajack }); } - public static IObservable DelayInitial(this IObservable source, TimeSpan delay) - { - return source.FlowSwitch( - Observable.Return(System.Reactive.Unit.Default) - .Delay(delay) - .Select(_ => true) - .StartWith(false)); - } - public static IObservable DelayInitial(this IObservable source, TimeSpan delay, IScheduler scheduler) { return source.FlowSwitch( diff --git a/Wabbajack/UI/FilePickerVM.cs b/Wabbajack/UI/FilePickerVM.cs index 1351e47e..4f20675a 100644 --- a/Wabbajack/UI/FilePickerVM.cs +++ b/Wabbajack/UI/FilePickerVM.cs @@ -80,7 +80,7 @@ namespace Wabbajack this.WhenAny(x => x.TargetPath) // Dont want to debounce the initial value, because we know it's null .Skip(1) - .Debounce(TimeSpan.FromMilliseconds(200), RxApp.TaskpoolScheduler) + .Debounce(TimeSpan.FromMilliseconds(200), RxApp.MainThreadScheduler) .StartWith(default(string)), resultSelector: (existsOption, type, path) => (ExistsOption: existsOption, Type: type, Path: path)) .StartWith((ExistsOption: ExistCheckOption, Type: PathType, Path: TargetPath)) diff --git a/Wabbajack/View Models/Compilers/CompilerVM.cs b/Wabbajack/View Models/Compilers/CompilerVM.cs index 65a579bb..48d5dfdc 100644 --- a/Wabbajack/View Models/Compilers/CompilerVM.cs +++ b/Wabbajack/View Models/Compilers/CompilerVM.cs @@ -123,7 +123,7 @@ namespace Wabbajack _image = this.WhenAny(x => x.CurrentModlistSettings.ImagePath.TargetPath) // Throttle so that it only loads image after any sets of swaps have completed - .Throttle(TimeSpan.FromMilliseconds(50), RxApp.TaskpoolScheduler) + .Throttle(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler) .DistinctUntilChanged() .ObserveOnGuiThread() .Select(path => @@ -174,7 +174,7 @@ namespace Wabbajack return compiler.PercentCompleted.StartWith(0); }) .Switch() - .Debounce(TimeSpan.FromMilliseconds(25)) + .Debounce(TimeSpan.FromMilliseconds(25), RxApp.MainThreadScheduler) .ToGuiProperty(this, nameof(PercentCompleted)); BeginCommand = ReactiveCommand.CreateFromTask( diff --git a/Wabbajack/View Models/Compilers/MO2CompilerVM.cs b/Wabbajack/View Models/Compilers/MO2CompilerVM.cs index 3c5191d6..4f924ef7 100644 --- a/Wabbajack/View Models/Compilers/MO2CompilerVM.cs +++ b/Wabbajack/View Models/Compilers/MO2CompilerVM.cs @@ -98,7 +98,7 @@ namespace Wabbajack (this).WhenAny(x => x.ModListLocation.TargetPath), resultSelector: (state, path) => (State: state, Path: path)) // A short throttle is a quick hack to make the above changes "atomic" - .Throttle(TimeSpan.FromMilliseconds(25)) + .Throttle(TimeSpan.FromMilliseconds(25), RxApp.MainThreadScheduler) .Select(u => { if (u.State.Failed) return null; @@ -142,7 +142,7 @@ namespace Wabbajack // If Mo2 folder changes and download location is empty, set it for convenience this.WhenAny(x => x.Mo2Folder) - .DelayInitial(TimeSpan.FromMilliseconds(100)) + .DelayInitial(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler) .Where(x => Directory.Exists(x)) .FlowSwitch( (this).WhenAny(x => x.DownloadLocation.Exists) diff --git a/Wabbajack/View Models/Installers/InstallerVM.cs b/Wabbajack/View Models/Installers/InstallerVM.cs index aae2f24a..f1dbf785 100644 --- a/Wabbajack/View Models/Installers/InstallerVM.cs +++ b/Wabbajack/View Models/Installers/InstallerVM.cs @@ -172,7 +172,7 @@ namespace Wabbajack return x.path; }) // Throttle slightly so changes happen more atomically - .Throttle(TimeSpan.FromMilliseconds(50)) + .Throttle(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler) .Replay(1) .RefCount(); @@ -192,7 +192,7 @@ namespace Wabbajack // Force GC collect when modlist changes, just to make sure we clean up any loose large items immediately this.WhenAny(x => x.ModList) - .Delay(TimeSpan.FromMilliseconds(50)) + .Delay(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler) .Subscribe(x => { GC.Collect(); @@ -252,7 +252,7 @@ namespace Wabbajack return installer.PercentCompleted.StartWith(0f); }) .Switch() - .Debounce(TimeSpan.FromMilliseconds(25)) + .Debounce(TimeSpan.FromMilliseconds(25), RxApp.MainThreadScheduler) .ToGuiProperty(this, nameof(PercentCompleted)); Slideshow = new SlideShow(this); diff --git a/Wabbajack/View Models/ModListGalleryVM.cs b/Wabbajack/View Models/ModListGalleryVM.cs index 6c95081f..5204b99c 100644 --- a/Wabbajack/View Models/ModListGalleryVM.cs +++ b/Wabbajack/View Models/ModListGalleryVM.cs @@ -52,7 +52,7 @@ namespace Wabbajack this.WhenAny(x => x.IsActive) .Where(x => !x) .Skip(1) - .Delay(TimeSpan.FromMilliseconds(50)) + .Delay(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler) .Subscribe(_ => { GC.Collect(); diff --git a/Wabbajack/View Models/SlideShow.cs b/Wabbajack/View Models/SlideShow.cs index 03099841..7a64cacd 100644 --- a/Wabbajack/View Models/SlideShow.cs +++ b/Wabbajack/View Models/SlideShow.cs @@ -66,7 +66,7 @@ namespace Wabbajack this.WhenAny(x => x.Installer.Installing), resultSelector: (enabled, installing) => enabled && installing)) // Block spam - .Debounce(TimeSpan.FromMilliseconds(250)) + .Debounce(TimeSpan.FromMilliseconds(250), RxApp.MainThreadScheduler) .Scan( seed: 0, accumulator: (i, _) => i + 1)