This BackgroundWorker is currently busy and cannot run multiple tasks concurrently

max stell 21 Reputation points
2022-09-09T21:51:30.587+00:00

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

239654-error.png

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();
}

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,828 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,247 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,570 questions
{count} votes