private void fireSearchStarted(SuggestedDisplaySortMode suggestedSortMode) { if (SearchStarted != null) { SearchStarted.Invoke(suggestedSortMode); } }
private async Task SearchAsync() { if (string.IsNullOrEmpty(mSearchString)) { return; } if (mSearchTask?.IsCanceled == false && mSearchTask?.IsCompleted == false) { //Cancel if previous search is running await CancelSearchAsync(); } xSearchBtn.Visibility = Visibility.Collapsed; xSearchClearBtn.Visibility = Visibility.Visible; mCancellationTokenSource = new CancellationTokenSource(); mSearchTask = new Task(() => { this.Dispatcher.Invoke(() => { try { mCancellationTokenSource.Token.ThrowIfCancellationRequested(); if (SearchStarted == null) { //If event is not hooked we say searching status on main window Reporter.ToStatus(eStatusMsgKey.Search, null, ": " + mSearchString); } else { //If event is hookded then no point in showing status on main window. //child window need to handle it in the window. E.g. Windows Explorer SearchStarted.Invoke(Tree, new EventArgs()); } Mouse.OverrideCursor = Cursors.Wait; xTreeViewTree.FilterItemsByText(xTreeViewTree.TreeItemsCollection, mSearchString, mCancellationTokenSource.Token); } catch (Exception ex) { Reporter.ToLog(eLogLevel.ERROR, "Failed to search : ", ex); } finally { if (SearchStarted == null) { Reporter.HideStatusMessage(); } else { SearchCompleted.Invoke(Tree, new EventArgs()); } Mouse.OverrideCursor = null; mCancellationTokenSource.Dispose(); } }); }, mCancellationTokenSource.Token, TaskCreationOptions.LongRunning); mSearchTask.Start(); }
protected virtual void OnSearchStarted(EventArgs args) { SearchStarted?.Invoke(this, args); }