I want to call the background worker synchronously. I want execution of the code to end when backgroundworker has completed its execution.
My code for BackgroundWorker is here :
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += DoWork;
worker.RunWorkerCompleted += RunWorkerCompleted;
...
worker.RunWorkerAsync();
//wait for execution to end
}
One way of doing it will be to check the status again n again until its execution is completed but is there any other good way of doing it ?
If you don’t want your code to execute asynchronously, don’t put it in a
BackgroundWorker…However, if there is some obscure reason why you absolutely need to have the code in the
BackgroundWorker, you can use the following: