private void task_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { buttonFind.Text = "Find"; task = null; labelStatus.Text = null; timerStatusUpdate.Stop(); }
private void buttonFind_Click(object sender, EventArgs e) { if (task == null) { if (String.IsNullOrEmpty(this.textBoxSearchFor.Text)) { MessageBox.Show("Search string can't be empty", clientApplication.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // validate seach root path string path = this.comboBoxSearchPath.Text; try { IFindInFilesNode rootNode = clientApplication.GetNodeForPath(path); rootNode.GetFiles(); } catch (Exception exception) { MessageBox.Show(String.Format("Search path is invalid: {0}", exception.Message), clientApplication.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } int pathIndex; if (!searchedPaths.TryGetValue(path, out pathIndex)) { pathIndex = pathCounter++; searchedPaths.Add(path, pathIndex); } lastPathNumber = pathIndex; int extensionIndex; if (!searchedExtensions.TryGetValue(comboBoxSearchExtensions.Text, out extensionIndex)) { extensionIndex = extensionCounter++; searchedExtensions.Add(comboBoxSearchExtensions.Text, extensionIndex); } lastExtensionNumber = extensionIndex; UpdateSettings(); if (!comboBoxSearchPath.Items.Contains(path)) { comboBoxSearchPath.Items.Add(path); comboBoxSearchPath.SelectedValue = path; } if (!comboBoxSearchExtensions.Items.Contains(comboBoxSearchExtensions.Text)) { string text = comboBoxSearchExtensions.Text; comboBoxSearchExtensions.Items.Add(text); comboBoxSearchExtensions.SelectedValue = text; } results.Clear(); task = new FindInFilesTask( this.textBoxSearchFor.Text, clientApplication.GetNodeForPath(path), comboBoxSearchExtensions.Text, this.checkBoxCaseSensitive.Checked, this.checkBoxMatchWholeWord.Checked); task.ProgressChanged += new ProgressChangedEventHandler(task_ProgressChanged); task.RunWorkerCompleted += new RunWorkerCompletedEventHandler(task_RunWorkerCompleted); buttonFind.Text = "Stop Find"; task.RunWorkerAsync(); timerStatusUpdate.Start(); dataGridViewFindResults.Focus(); } else { task.CancelAsync(); task.ProgressChanged -= new ProgressChangedEventHandler(task_ProgressChanged); task.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(task_RunWorkerCompleted); buttonFind.Text = "Find"; task = null; labelStatus.Text = null; timerStatusUpdate.Stop(); } }