private void button1_Click(object sender, EventArgs e)
{
//progress bar
backgroundWorker1.RunWorkerAsync();
progressBar1.Value = 1;
progressBar1.Minimum = 1;
progressBar1.Maximum = 10;
label3.Text = "backgroundworker Task completed";
Thread.Sleep(100);
Application.DoEvents();
// end of bgw
}
I am getting error on the Backgroundworker1.RunworkerAsync() where it shows an error of Backgroundworker is busy and try to use it aftertime.
Is there any other method to solve. I thank in advance.
When you call
RunWorkerAsync, theIsBusyproperty will returnTrue. TheBackgroundWorkerwill raise itsDoWorkevent and you do your background work in that event handler. Once that event handler completes, it will raise itsRunWorkerCompletedevent and you can optionally handle that event to update the UI after the background work. Once the event handlers for both events complete, theIsBusyproperty will returnFalse. The whole point of that property is to tell you that theBackgroundWorkeris already busy so you shouldn't callRunWorkerAsync. The solution to your problem is not callRunWorkerAsyncuntilIsBusyisFalseagain, e.g.