From ebddf19ba21beccd961c3ad245640053e50fda3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Wed, 11 Nov 2020 19:06:05 +0800 Subject: [PATCH] Fix not canceled token and adding comment Co-authored-by: bao-qian --- Flow.Launcher/ViewModel/MainViewModel.cs | 6 ++++-- Flow.Launcher/ViewModel/ResultsViewModel.cs | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 0a1ef8d81..f71674774 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -469,9 +469,9 @@ namespace Flow.Launcher.ViewModel } else { + _updateSource?.Cancel(); Results.Clear(); Results.Visbility = Visibility.Collapsed; - } } @@ -695,7 +695,9 @@ namespace Flow.Launcher.ViewModel _saved = true; } } - + /// + /// To avoid deadlock, this method should not called from main thread + /// public void UpdateResultView(IEnumerable resultsForUpdates) { foreach (var result in resultsForUpdates.SelectMany(u => u.Results)) diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index d06a390c5..635b20ec6 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -174,7 +174,6 @@ namespace Flow.Launcher.ViewModel Margin = new Thickness { Top = 0 }; Visbility = Visibility.Collapsed; break; - } } @@ -247,7 +246,7 @@ namespace Flow.Launcher.ViewModel public class ResultCollection : ObservableCollection, INotifyCollectionChanged { - public event NotifyCollectionChangedEventHandler CollectionChanged; + public override event NotifyCollectionChangedEventHandler CollectionChanged; public void RemoveAll() { ClearItems(); @@ -259,12 +258,16 @@ namespace Flow.Launcher.ViewModel /// public void Update(List newItems) { + + ClearItems(); foreach (var item in newItems) { Add(item); } + + // wpf use directx / double buffered already, so just reset all won't cause ui flickering CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); return;