From b156afed0bdac5cbe19749fcad2687d4bf2b9e20 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 6 May 2025 14:14:10 +0800 Subject: [PATCH] Revert "Add update source lock" This reverts commit 265fd9c868e881da4f61060bb40385268c8d6420. --- Flow.Launcher/ViewModel/MainViewModel.cs | 27 ++++++------------------ 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index afef8f64e..175f4ff84 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -47,7 +47,6 @@ namespace Flow.Launcher.ViewModel private CancellationTokenSource _updateSource; // Used to cancel old query flows private CancellationToken _updateToken; // Used to avoid ObjectDisposedException of _updateSource.Token - private readonly object _updateSourceLock = new(); private ChannelWriter _resultsUpdateChannelWriter; private Task _resultsViewUpdateTask; @@ -70,11 +69,8 @@ namespace Flow.Launcher.ViewModel _queryText = ""; _lastQuery = new Query(); _ignoredQueryText = null; // null as invalid value - lock (_updateSourceLock) - { - _updateSource = new CancellationTokenSource(); - _updateToken = _updateSource.Token; - } + _updateSource = new CancellationTokenSource(); + _updateToken = _updateSource.Token; Settings = Ioc.Default.GetRequiredService(); Settings.PropertyChanged += (_, args) => @@ -1244,10 +1240,7 @@ namespace Flow.Launcher.ViewModel private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, bool reSelect = true) { - lock (_updateSourceLock) - { - _updateSource.Cancel(); - } + _updateSource?.Cancel(); App.API.LogDebug(ClassName, $"Start query with text: <{QueryText}>"); @@ -1275,12 +1268,9 @@ namespace Flow.Launcher.ViewModel var isHomeQuery = query.RawQuery == string.Empty; - lock (_updateSourceLock) - { - _updateSource.Dispose(); // Dispose old update source to fix possible cancellation issue - _updateSource = new CancellationTokenSource(); - _updateToken = _updateSource.Token; - } + _updateSource?.Dispose(); // Dispose old update source to fix possible cancellation issue + _updateSource = new CancellationTokenSource(); + _updateToken = _updateSource.Token; ProgressBarVisibility = Visibility.Hidden; _isQueryRunning = true; @@ -1898,10 +1888,7 @@ namespace Flow.Launcher.ViewModel { if (disposing) { - lock (_updateSourceLock) - { - _updateSource?.Dispose(); - } + _updateSource?.Dispose(); _resultsUpdateChannelWriter?.Complete(); if (_resultsViewUpdateTask?.IsCompleted == true) {