diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs index ecadd61ecb9..22d89ba8fff 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs @@ -63,10 +63,6 @@ internal async static Task> ExecuteWindowsIndexSearchAsync(string i } } } - catch (OperationCanceledException) - { - return new List(); // The source code indicates that without adding members, it won't allocate an array - } catch (InvalidOperationException e) { // Internal error from ExecuteReader(): Connection closed. @@ -95,12 +91,13 @@ internal async static Task> WindowsIndexSearchAsync(string searchSt return new List(); var constructedQuery = constructQuery(searchString); - return await RemoveResultsInExclusionList( - await ExecuteWindowsIndexSearchAsync(constructedQuery, connectionString, query, token), - exclusionList); + return RemoveResultsInExclusionList( + await ExecuteWindowsIndexSearchAsync(constructedQuery, connectionString, query, token).ConfigureAwait(false), + exclusionList, + token); } - private async static Task> RemoveResultsInExclusionList(List results, List exclusionList) + private static List RemoveResultsInExclusionList(List results, List exclusionList, CancellationToken token) { var indexExclusionListCount = exclusionList.Count; @@ -109,25 +106,26 @@ private async static Task> RemoveResultsInExclusionList(List(); - await Task.Run(() => + for (var index = 0; index < results.Count; index++) { - for (var index = 0; index < results.Count; index++) + token.ThrowIfCancellationRequested(); + + var excludeResult = false; + + for (var i = 0; i < indexExclusionListCount; i++) { - var excludeResult = false; + token.ThrowIfCancellationRequested(); - for (var i = 0; i < indexExclusionListCount; i++) + if (results[index].SubTitle.StartsWith(exclusionList[i].Path, StringComparison.OrdinalIgnoreCase)) { - if (results[index].SubTitle.StartsWith(exclusionList[i].Path, StringComparison.OrdinalIgnoreCase)) - { - excludeResult = true; - break; - } + excludeResult = true; + break; } - - if (!excludeResult) - filteredResults.Add(results[index]); } - }); + + if (!excludeResult) + filteredResults.Add(results[index]); + } return filteredResults; } diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs index d0347fa670c..0f6968092b2 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs @@ -50,35 +50,21 @@ public async Task> QueryAsync(Query query, CancellationToken token) win32 = _win32s; uwps = _uwps; - try + var result = await Task.Run(delegate { - var result = await Task.Run(delegate - { - try - { - return win32.Cast() - .Concat(uwps) - .AsParallel() - .WithCancellation(token) - .Where(p => p.Enabled) - .Select(p => p.Result(query.Search, _context.API)) - .Where(r => r?.Score > 0) - .ToList(); - } - catch (OperationCanceledException) - { - return null; - } - }, token).ConfigureAwait(false); - - token.ThrowIfCancellationRequested(); - - return result; - } - catch (OperationCanceledException) - { - return null; - } + return win32.Cast() + .Concat(uwps) + .AsParallel() + .WithCancellation(token) + .Where(p => p.Enabled) + .Select(p => p.Result(query.Search, _context.API)) + .Where(r => r?.Score > 0) + .ToList(); + }, token).ConfigureAwait(false); + + token.ThrowIfCancellationRequested(); + + return result; } public async Task InitAsync(PluginInitContext context) diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs index 94458ff5203..ccb5b20d730 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs @@ -30,11 +30,6 @@ public override async Task> Suggestions(string query, CancellationT Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e); return null; } - catch (OperationCanceledException) - { - return null; - } - if (string.IsNullOrEmpty(result)) return new List(); Match match = _reg.Match(result); diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs index 966a6ca16db..38c5fb4a0f8 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs @@ -45,10 +45,6 @@ public override async Task> Suggestions(string query, CancellationT Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e); return null; } - catch (OperationCanceledException) - { - return new List(); - } catch (JsonException e) { Log.Exception("|Bing.Suggestions|can't parse suggestions", e); diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs index 91ab921b634..c5f43d081be 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs @@ -37,10 +37,6 @@ public override async Task> Suggestions(string query, CancellationT Log.Exception("|Baidu.Suggestions|Can't get suggestion from baidu", e); return null; } - catch (OperationCanceledException) - { - return new List(); - } catch (JsonException e) { Log.Exception("|Google.Suggestions|can't parse suggestions", e);