public async void RunSearch() { ImportPeptideSearch.SearchEngine.SearchProgressChanged += SearchEngine_MessageNotificationEvent; txtSearchProgress.Text = string.Empty; _progressTextItems.Clear(); btnCancel.Enabled = true; ProgressStatus status = new ProgressStatus(Resources.DDASearchControl_SearchProgress_Starting_search); progressBar.Visible = true; UpdateSearchEngineProgress(status); cancelToken = new CancellationTokenSource(); t = Task <bool> .Factory.StartNew(() => ImportPeptideSearch.SearchEngine.Run(cancelToken), cancelToken.Token); await t; if (cancelToken.IsCancellationRequested) { UpdateSearchEngineProgress(status.ChangeMessage(Resources.DDASearchControl_SearchProgress_Search_canceled)); progressBar.Visible = false; } else if (!t.Result) { UpdateSearchEngineProgress(status.ChangeWarningMessage(Resources.DDASearchControl_SearchProgress_Search_failed)); } else { UpdateSearchEngineProgress(status.ChangeMessage(Resources.DDASearchControl_SearchProgress_Search_done).Complete()); } UpdateTaskbarProgress(TaskbarProgress.TaskbarStates.NoProgress, 0); btnCancel.Enabled = false; OnSearchFinished?.Invoke(t.Result); ImportPeptideSearch.SearchEngine.SearchProgressChanged -= SearchEngine_MessageNotificationEvent; }
/// <summary> /// The constructor for getting callbacks. null values are acceptable /// </summary> /// <param name="finishedCallback"></param> /// <param name="directorySearchStartedCallback"></param> /// <param name="fileSearchStartedcallback"></param> /// <param name="fileMatchedCallback"></param> public SignFinder(OnSearchFinished finishedCallback, OnDirectorySearchStarted directorySearchStartedCallback, OnFileSearchStarted fileSearchStartedcallback, OnFileMatched fileMatchedCallback) { this.finishedCallback = finishedCallback; this.directorySearchStartedCallback = directorySearchStartedCallback; this.fileSearchStartedcallback = fileSearchStartedcallback; this.fileMatchedCallback = fileMatchedCallback; }