From 524d05c078f9a9fe6e5ad3f2328f410c6ff03b8c Mon Sep 17 00:00:00 2001 From: Mikael Svenson Date: Mon, 3 Feb 2020 09:47:42 +0100 Subject: [PATCH] Proper UI threading fix. Bumped to v2.8.6 --- .../SearchQueryTool/MainWindow.xaml.cs | 130 ++++++++++-------- .../Properties/AssemblyInfo.cs | 4 +- 2 files changed, 76 insertions(+), 58 deletions(-) diff --git a/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/MainWindow.xaml.cs b/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/MainWindow.xaml.cs index 7efba6d9..72352487 100644 --- a/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/MainWindow.xaml.cs +++ b/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/MainWindow.xaml.cs @@ -1080,51 +1080,63 @@ private void StartSearchQueryRequest() private void SetHitStatus(SearchQueryResult searchResults) { - if (null != searchResults) + this.Dispatcher.Invoke(() => { - var totalRows = 0; - var queryElapsedTime = "0"; - if (null != searchResults.QueryElapsedTime) + if (null != searchResults) { - queryElapsedTime = searchResults.QueryElapsedTime; - } + var totalRows = 0; + var queryElapsedTime = "0"; + if (null != searchResults.QueryElapsedTime) + { + queryElapsedTime = searchResults.QueryElapsedTime; + } - if (null != searchResults.PrimaryQueryResult) - { - totalRows = searchResults.PrimaryQueryResult.TotalRows; + if (null != searchResults.PrimaryQueryResult) + { + totalRows = searchResults.PrimaryQueryResult.TotalRows; + } + HitStatusTextBlock.Text = String.Format("{0} hits in {1} ms", totalRows, queryElapsedTime); } - HitStatusTextBlock.Text = String.Format("{0} hits in {1} ms", totalRows, queryElapsedTime); - } + }); } private void RequestStarted() { - ConnectionExpanderBox.Foreground = Brushes.Purple; - HitStatusTextBlock.Text = "..."; + this.Dispatcher.Invoke(() => + { + ConnectionExpanderBox.Foreground = Brushes.Purple; + HitStatusTextBlock.Text = "..."; + }); } private void RequestSuccessful() { - ConnectionExpanderBox.IsExpanded = false; - ConnectionExpanderBox.Foreground = Brushes.Green; - RequestUriLengthTextBox.Foreground = Brushes.Gray; - HitStatusTextBlock.Foreground = Brushes.Black; + this.Dispatcher.Invoke(() => + { + ConnectionExpanderBox.IsExpanded = false; + ConnectionExpanderBox.Foreground = Brushes.Green; + RequestUriLengthTextBox.Foreground = Brushes.Gray; + HitStatusTextBlock.Foreground = Brushes.Black; - // Save this successful item to our history - History.SaveHistoryItem(); + // Save this successful item to our history + History.SaveHistoryItem(); - // Reload entire history list and reset the current point to the latest entry - SearchHistory = new SearchHistory(HistoryFolderPath); - History.RefreshHistoryButtonState(); + // Reload entire history list and reset the current point to the latest entry + SearchHistory = new SearchHistory(HistoryFolderPath); + History.RefreshHistoryButtonState(); - RefreshBreadCrumbs(); + RefreshBreadCrumbs(); + }); } private void RequestFailed() { - ConnectionExpanderBox.Foreground = Brushes.Red; - HitStatusTextBlock.Foreground = Brushes.Red; - RequestUriLengthTextBox.Foreground = Brushes.Red; + this.Dispatcher.Invoke(() => + { + ConnectionExpanderBox.Foreground = Brushes.Red; + HitStatusTextBlock.Foreground = Brushes.Red; + RequestUriLengthTextBox.Foreground = Brushes.Red; + }); } private Button GetHiddenConstraintsButton(string text) @@ -1186,37 +1198,40 @@ private static List ParseHiddenConstraints(string input) private void RefreshBreadCrumbs() { - // Clear old hidden constraints - HiddenConstraintWrapPanel.Children.Clear(); + this.Dispatcher.Invoke(() => + { + // Clear old hidden constraints + HiddenConstraintWrapPanel.Children.Clear(); - // ParseHiddenConstraints hidden constraints and populate panel with new breadcrumb buttons - var hiddenConstraints = HiddenConstraintsTextBox.Text; + // ParseHiddenConstraints hidden constraints and populate panel with new breadcrumb buttons + var hiddenConstraints = HiddenConstraintsTextBox.Text; - if (string.IsNullOrWhiteSpace(hiddenConstraints)) - { - // Initialize state when we have no hidden constraints - ExpanderHiddenConstraints.Header = String.Format("Hidden Constraints"); - BreadCrumbDockPanel.Visibility = Visibility.Collapsed; - } - else - { - // Extract patterns like with quotes and space, e.g.: ContentSource:"Local SharePoint" - var list = ParseHiddenConstraints(hiddenConstraints); - if (list.Any()) + if (string.IsNullOrWhiteSpace(hiddenConstraints)) { - ExpanderHiddenConstraints.Header = String.Format("Hidden Constraints ({0})", list.Count()); - foreach (var button in list.Select(GetHiddenConstraintsButton)) - { - HiddenConstraintWrapPanel.Children.Add(button); - } - BreadCrumbDockPanel.Visibility = Visibility.Visible; + // Initialize state when we have no hidden constraints + ExpanderHiddenConstraints.Header = String.Format("Hidden Constraints"); + BreadCrumbDockPanel.Visibility = Visibility.Collapsed; } else { - // Hide breadcrumbs when there are no matches - BreadCrumbDockPanel.Visibility = Visibility.Collapsed; + // Extract patterns like with quotes and space, e.g.: ContentSource:"Local SharePoint" + var list = ParseHiddenConstraints(hiddenConstraints); + if (list.Any()) + { + ExpanderHiddenConstraints.Header = String.Format("Hidden Constraints ({0})", list.Count()); + foreach (var button in list.Select(GetHiddenConstraintsButton)) + { + HiddenConstraintWrapPanel.Children.Add(button); + } + BreadCrumbDockPanel.Visibility = Visibility.Visible; + } + else + { + // Hide breadcrumbs when there are no matches + BreadCrumbDockPanel.Visibility = Visibility.Collapsed; + } } - } + }); } private void HiddenConstraintsRemoveButton_OnClick(object sender, RoutedEventArgs e) @@ -2590,12 +2605,15 @@ private void MarkRequestOperation(bool starting, string status) /// private void ClearResultTabs() { - StatsResultTabItem.Content = null; - RawResultTabItem.Content = null; - PrimaryResultsTabItem.Content = null; - RefinementResultsTabItem.Content = null; - SecondaryResultsTabItem.Content = null; - SuggestionResultsTabItem.Content = null; + this.Dispatcher.Invoke(() => + { + StatsResultTabItem.Content = null; + RawResultTabItem.Content = null; + PrimaryResultsTabItem.Content = null; + RefinementResultsTabItem.Content = null; + SecondaryResultsTabItem.Content = null; + SuggestionResultsTabItem.Content = null; + }); } /// diff --git a/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/Properties/AssemblyInfo.cs b/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/Properties/AssemblyInfo.cs index 1879e40d..e82fcbd2 100644 --- a/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/Properties/AssemblyInfo.cs +++ b/Solutions/SharePoint.Search.QueryTool/SearchQueryTool/Properties/AssemblyInfo.cs @@ -50,6 +50,6 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.8.5.0")] -[assembly: AssemblyFileVersion("2.8.5.0")] +[assembly: AssemblyVersion("2.8.6.0")] +[assembly: AssemblyFileVersion("2.8.6.0")] [assembly: NeutralResourcesLanguageAttribute("en")]