diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/WindowsIndex/IndexSearch.cs index ecadd61ec..22d89ba8f 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 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex } } } - 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 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex 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 @@ namespace Flow.Launcher.Plugin.Explorer.Search.WindowsIndex var filteredResults = new 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 d0347fa67..0f6968092 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs @@ -50,35 +50,21 @@ namespace Flow.Launcher.Plugin.Program 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); + 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(); + token.ThrowIfCancellationRequested(); - return result; - } - catch (OperationCanceledException) - { - return null; - } + 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 94458ff52..ccb5b20d7 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs @@ -30,11 +30,6 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources 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 966a6ca16..38c5fb4a0 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs @@ -45,10 +45,6 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources 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 91ab921b6..c5f43d081 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs @@ -37,10 +37,6 @@ namespace Flow.Launcher.Plugin.WebSearch.SuggestionSources 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);