background worker cancel problem

S

Smokey Grindel

I have a search function that runs in a background worker which can run
long.. I want the user to be able to cancel that then run another search...
but sometimes it throws an exception saying

System.InvalidOperationException: This BackgroundWorker is currently busy
and cannot run multiple tasks concurrently.

What I did before the search button was pressed again was check if the
worker is busy and if it is cancel the current search then start another...
now how can i make sure the worker isnt workering before trying to start
another? Even though I cancelled the work some work might still be
processing before it realizes its cancelled and thats what seems to be
causing the error... thanks!
 
R

Ryan Jones

You might be able to use a loop to look the current thread until you background worker is finished:

While MyBackgroundWorker.IsBusy

End While
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top