private void BeginVolumeSearch() { ISearchCriteria criteria = null; if (txtSearchString.Text.Length > 0) { try { criteria = new EUSLSearchCriteria(txtSearchString.Text); } catch (ArgumentException e) { SetTempStatus(Util.FormatExceptionMsg(e)); return; } } System.Action oncompleted = () => { Application.Invoke(delegate { // treeview filling has stolen the focus. txtSearchString.GrabFocus(); }); }; SearchVolumeAsync(criteria, oncompleted); }
private void BeginSearch() { // make sure searching is enabled // (searchstring may be too short) if (!btnSearch.Sensitive) { return; } ISearchCriteria criteria = null; try { criteria = new EUSLSearchCriteria(txtSearchString.Text); } catch (ArgumentException e) { SetStatus(Util.FormatExceptionMsg(e)); return; } // callback called when searching has been finished AsyncCallback callback = ar => { if (windowDeleted) { return; } try { VolumeItem[] items = database.EndSearchItem(ar); Application.Invoke((o, args) => { // calls selection changed handler // that fills the searchrestult view tvCategory.Categorize(items); TimeSpan time = DateTime.Now.Subtract((DateTime)ar.AsyncState); SetStatus(string.Format(S._("Found {0} items in {1:F3} seconds."), items.Length, time.TotalSeconds)); }); } catch (Exception e) { Application.Invoke((o, args) => { tvCategory.Clear(); navi.Clear(); tvSearchResult.Clear(); }); if (e is TimeoutException) { // couldn't get connection lock Application.Invoke((o, args) => SetStatus(S._("Timeout: another search is probably still in progress."))); } else if (e is TooManyResultsException) { Application.Invoke((o, args) => SetStatus(S._("Too many search results. Please refine your search criteria."))); } else { //Application.Invoke((o, args) => SetStatus(Util.FormatExceptionMsg(e))); Application.Invoke((o, args) => SetStatus(string.Empty)); throw; } } finally { Application.Invoke((o, args) => { itemInfo.Clear(); itemInfo.Hide(); }); } }; try { infoBar.Visible = false; navi.Visible = true; SetStatus(S._("Searching...")); database.BeginSearchItem(criteria, callback, DateTime.Now); } catch (Exception) { SetStatus(string.Empty); throw; } }