background worker cancel problem

  • Thread starter Thread starter Smokey Grindel
  • Start date Start date
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!
 
You might be able to use a loop to look the current thread until you background worker is finished:

While MyBackgroundWorker.IsBusy

End While
 
Back
Top