From bfaff5cca5eeb71254ca51b463a1cd0b876e788c Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Thu, 6 Nov 2025 15:32:08 +0800 Subject: [PATCH] Improve semaphore usage and logging clarity Added comments in `EverythingAPI.cs` and `Main.cs` to explain why `CancellationToken` is not directly passed to semaphore locks, preventing unexpected `OperationCanceledException`. Updated debug log messages in `Main.cs` for better clarity, including changing "Start handling programs" to "Start querying programs". Removed redundant log messages to improve logging consistency. --- .../Search/Everything/EverythingAPI.cs | 2 ++ Plugins/Flow.Launcher.Plugin.Program/Main.cs | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs index 28c9b49fc..c8f8de77f 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs @@ -48,6 +48,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything public static async ValueTask IsEverythingRunningAsync(CancellationToken token = default) { + // We do not directly pass token here, but we check IsCancellationRequested inside the lock + // So that it will not raise OperationCanceledException, which is not expected by the caller.` await _semaphore.WaitAsync(); try diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs index a2dfecff4..6a8b404b5 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs @@ -84,6 +84,8 @@ namespace Flow.Launcher.Plugin.Program { var resultList = await Task.Run(async () => { + // We do not directly pass token here, but we check IsCancellationRequested inside the lock + // So that it will not raise OperationCanceledException, which is not expected by the caller.` Context.API.LogDebug(ClassName, "Preparing win32 programs"); List win32s; await _win32sLock.WaitAsync(); @@ -97,6 +99,8 @@ namespace Flow.Launcher.Plugin.Program _win32sLock.Release(); } + // We do not directly pass token here, but we check IsCancellationRequested inside the lock + // So that it will not raise OperationCanceledException, which is not expected by the caller.` Context.API.LogDebug(ClassName, "Preparing UWP programs"); List uwps; await _uwpsLock.WaitAsync(); @@ -110,7 +114,7 @@ namespace Flow.Launcher.Plugin.Program _uwpsLock.Release(); } - Context.API.LogDebug(ClassName, "Start hanlding programs"); + Context.API.LogDebug(ClassName, "Start querying programs"); try { // Collect all UWP Windows app directories @@ -324,7 +328,6 @@ namespace Flow.Launcher.Plugin.Program public static async Task IndexWin32ProgramsAsync() { - Context.API.LogDebug(ClassName, "Prepare indexing Win32 programs"); await _win32sLock.WaitAsync(); Context.API.LogDebug(ClassName, "Start indexing Win32 programs"); try @@ -354,7 +357,6 @@ namespace Flow.Launcher.Plugin.Program public static async Task IndexUwpProgramsAsync() { - Context.API.LogDebug(ClassName, "Prepare indexing Uwp programs"); await _uwpsLock.WaitAsync(); Context.API.LogDebug(ClassName, "Start indexing Uwp programs"); try