From 19c7446552f6242cc43981948ea5eb24783f5dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Wed, 2 Dec 2020 13:56:50 +0800 Subject: [PATCH] Add Lock to the place we directly update the ResultCollection --- Flow.Launcher/ViewModel/ResultsViewModel.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index 6d476ec63..d373b0fda 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -120,17 +120,20 @@ namespace Flow.Launcher.ViewModel public void Clear() { - Results.RemoveAll(); + lock (_collectionLock) + Results.RemoveAll(); } public void KeepResultsFor(PluginMetadata metadata) { - Results.Update(Results.Where(r => r.Result.PluginID == metadata.ID).ToList()); + lock (_collectionLock) + Results.Update(Results.Where(r => r.Result.PluginID == metadata.ID).ToList()); } public void KeepResultsExcept(PluginMetadata metadata) { - Results.Update(Results.Where(r => r.Result.PluginID != metadata.ID).ToList()); + lock (_collectionLock) + Results.Update(Results.Where(r => r.Result.PluginID != metadata.ID).ToList()); } @@ -148,7 +151,8 @@ namespace Flow.Launcher.ViewModel // update UI in one run, so it can avoid UI flickering Results.Update(newResults); - SelectedItem = newResults[0]; + if (newResults.Any()) + SelectedItem = newResults[0]; } if (Visbility != Visibility.Visible && Results.Count > 0) @@ -304,6 +308,9 @@ namespace Flow.Launcher.ViewModel OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } + + + /// /// Update the results collection with new results, try to keep identical results /// @@ -311,9 +318,9 @@ namespace Flow.Launcher.ViewModel /// Cancellation Token public void Update(List newItems, CancellationToken? token = null) { - if (newItems.Count == 0 || (token?.IsCancellationRequested ?? false)) + if (token?.IsCancellationRequested ?? false) return; - + if (editTime < 5 || newItems.Count < 30) {