diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/SearchHelper/OleDBSearch.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/SearchHelper/OleDBSearch.cs index fd80d71873..027af76b22 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/SearchHelper/OleDBSearch.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Indexer/SearchHelper/OleDBSearch.cs @@ -28,26 +28,35 @@ namespace Microsoft.Plugin.Indexer.SearchHelper // open the connection conn.Open(); - // now create an OleDB command object with the query we built above and the connection we just opened. - using (command = new OleDbCommand(sqlQuery, conn)) + try { - using (wDSResults = command.ExecuteReader()) + // now create an OleDB command object with the query we built above and the connection we just opened. + using (command = new OleDbCommand(sqlQuery, conn)) { - if (!wDSResults.IsClosed && wDSResults.HasRows) + using (wDSResults = command.ExecuteReader()) { - while (!wDSResults.IsClosed && wDSResults.Read()) + if (!wDSResults.IsClosed && wDSResults.HasRows) { - List fieldData = new List(); - for (int i = 0; i < wDSResults.FieldCount; i++) + while (!wDSResults.IsClosed && wDSResults.Read()) { - fieldData.Add(wDSResults.GetValue(i)); - } + List fieldData = new List(); + for (int i = 0; i < wDSResults.FieldCount; i++) + { + fieldData.Add(wDSResults.GetValue(i)); + } - result.Add(new OleDBResult(fieldData)); + result.Add(new OleDBResult(fieldData)); + } } } } } + + // AccessViolationException can occur if another query is made before the current query completes. Since the old query would be cancelled we can ignore the exception + catch (System.AccessViolationException) + { + // do nothing + } } return result; diff --git a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs index 3b84fddcef..cdc8994088 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs @@ -512,33 +512,40 @@ namespace PowerLauncher.ViewModel currentCancellationToken.ThrowIfCancellationRequested(); Parallel.ForEach(plugins, (plugin) => { - if (!plugin.Metadata.Disabled) + try { - var results = PluginManager.QueryForPlugin(plugin, query, true); - currentCancellationToken.ThrowIfCancellationRequested(); - if ((results?.Count ?? 0) != 0) + if (!plugin.Metadata.Disabled) { - lock (_addResultsLock) - { - if (query.RawQuery == _currentQuery.RawQuery) - { - currentCancellationToken.ThrowIfCancellationRequested(); - - // Remove the original results from the plugin - Results.Results.RemoveAll(r => r.Result.PluginID == plugin.Metadata.ID); - currentCancellationToken.ThrowIfCancellationRequested(); - - // Add the new results from the plugin - UpdateResultView(results, query, currentCancellationToken); - currentCancellationToken.ThrowIfCancellationRequested(); - Results.Sort(); - } - } - + var results = PluginManager.QueryForPlugin(plugin, query, true); currentCancellationToken.ThrowIfCancellationRequested(); - UpdateResultsListViewAfterQuery(query, true); + if ((results?.Count ?? 0) != 0) + { + lock (_addResultsLock) + { + if (query.RawQuery == _currentQuery.RawQuery) + { + currentCancellationToken.ThrowIfCancellationRequested(); + + // Remove the original results from the plugin + Results.Results.RemoveAll(r => r.Result.PluginID == plugin.Metadata.ID); + currentCancellationToken.ThrowIfCancellationRequested(); + + // Add the new results from the plugin + UpdateResultView(results, query, currentCancellationToken); + currentCancellationToken.ThrowIfCancellationRequested(); + Results.Sort(); + } + } + + currentCancellationToken.ThrowIfCancellationRequested(); + UpdateResultsListViewAfterQuery(query, true); + } } } + catch (OperationCanceledException) + { + // nothing to do here + } }); }