From 2f4e140fb0a6742ddae311c2c71f00540d663cd7 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 21 Mar 2025 10:03:53 +0800 Subject: [PATCH] Improve query async local function --- Flow.Launcher/ViewModel/MainViewModel.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 7e64c6a28..2673a92d1 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -1204,16 +1204,20 @@ namespace Flow.Launcher.ViewModel } // Local function - async Task QueryTaskAsync(PluginPair plugin, bool reSelect = true) + async ValueTask QueryTaskAsync(PluginPair plugin, bool reSelect = true) { // Since it is wrapped within a ThreadPool Thread, the synchronous context is null // Task.Yield will force it to run in ThreadPool await Task.Yield(); + if (_updateSource.Token.IsCancellationRequested) + return; + IReadOnlyList results = await PluginManager.QueryForPluginAsync(plugin, query, _updateSource.Token); - _updateSource.Token.ThrowIfCancellationRequested(); + if (_updateSource.Token.IsCancellationRequested) + return; IReadOnlyList resultsCopy; if (results == null)