This BackgroundWorker is currently busy and cannot run multiple tasks concurrently

Jade M picture Jade M · Feb 25, 2009 · Viewed 67.7k times · Source

I get this error if I click a button that starts the backgroundworker twice.

This BackgroundWorker is currently busy and cannot run multiple tasks concurrently

How can I avoid this?

Answer

Orion Edwards picture Orion Edwards · Feb 25, 2009

Simple: Don't start the BackgroundWorker twice.

You can check if it is already running by using the IsBusy property, so just change this code:

worker.RunWorkerAsync();

to this:

if( !worker.IsBusy )
    worker.RunWorkerAsync();
else
    MessageBox.Show("Can't run the worker twice!");

Update:

If you do actually need to launch multiple background tasks at the same time, you can simply create multiple BackgroundWorker objects