/// <summary> /// Главный поток, который производит поиск, запускает по нажатию на button1 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { find_file find_File = new find_file(); find_File.find(path, rex, this, ref not_over); backgroundWorker2.WorkerSupportsCancellation = true; backgroundWorker2.CancelAsync(); button1.BeginInvoke((Action)(() => button1.Enabled = true)); button2.BeginInvoke((Action)(() => button2.Enabled = false)); }
/// <summary> /// Поток для продолжения поиска при прерывании /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundWorker3_DoWork(object sender, DoWorkEventArgs e) { for (int i = 0; i < not_over.Count; i++) { if (backgroundWorker3.CancellationPending) { return; } string sub = not_over[0]; not_over.RemoveAt(0); find_file find_File = new find_file(); find_File.find(sub, rex, this, ref not_over); } backgroundWorker2.WorkerSupportsCancellation = true; backgroundWorker2.CancelAsync(); button1.BeginInvoke((Action)(() => button1.Enabled = true)); button2.BeginInvoke((Action)(() => button2.Enabled = false)); }