This BackgroundWorker is currently busy and cannot run multiple tasks concurrently
Help Please How I can Run Multiple task And How To Add A button To Stop The Search and in the same time stop the BackgroundWorker
the code :
public partial class Form1 : Form
{
private Searcher searcher;
public Form1()
{
InitializeComponent();
this.searcher = new Searcher(null, null,null);
this.searcher.onFileFound += FileFound;
bgWorker.DoWork += WorkInBackground;
bgWorker.RunWorkerCompleted += WorkerCompleted;
}
private void FileFound(string path)
{
listBox1.BeginInvoke((Action)delegate ()
{
listBox1.Items.Add(path);
});
}
private void WorkerCompleted(object sender, RunWorkerCompletedEventArgs args)
{
textBox3.Text = listBox1.Items.Count.ToString();
MessageBox.Show("Search is Done");
}
private void WorkInBackground(object sender, DoWorkEventArgs args)
{
searcher.Search();
}