private void Async_PerformSearch(Object arg) { if (arg == null) { return; } var par = (SearchAsyncParam)arg; // new request was added - this one is outdated if (par.SequenceNumber < _requestSequenceNumber) { return; } if (SameAsPreviousSearch(par)) { return; } SetStatus("Searching '" + par.Text + "' in " + par.Database, true); var result = StudioController.Find(par.Srv, par.Database, par.Text, _cfg.LimitSearch); // new request was added - this one is outdated if (par.SequenceNumber < _requestSequenceNumber) { log.Info("Cancelled search request because new request was added. " + par.Text); return; } SetStatus("Found " + result.Count + " objects"); InvokeInUI(() => { log.Info("Updating UI items"); var analyzer = new PerformanceAnalyzer(); var items = ItemFactory.BuildFromEntries(result); itemsControl.ItemsSource = items; itemsControl.SelectedIndex = -1; itemsControl.ScrollIntoView(itemsControl.SelectedItem); if (items.Count == 0) { gridEmptyResult.Visibility = System.Windows.Visibility.Visible; itemsControl.Visibility = System.Windows.Visibility.Collapsed; } else { gridEmptyResult.Visibility = System.Windows.Visibility.Collapsed; itemsControl.Visibility = System.Windows.Visibility.Visible; } log.Performance("UI items updated", analyzer.Result); analyzer.Stop(); }); if (result.Count == 0) { SetStatus("Found nothing. Try to refresh"); } else if (result.Count == 1) { SetStatus("Found exactly one object"); } else { SetStatus("Found " + result.Count + " objects "); } }