I have a problem when it comes to cancel a backgroundworker from working.
I start the backgroundworker successfully and the worker supports cancellation is set to true.

What I do is to use a button that both can run the backgroundworker and next time you press the same button, it is ment to cancel the backgroundworker so you can press it again to run the worker again and so on.
When I press the backgroundworker the second time to cancel it with the:

...and then if I press the button again, I get this errormessage that says that the backgroundworker is currently busy and cannot run multiple tasks concurrently ?

To run the worker works fine, all processes is starting !


When I try to cancel the worker, it seems that the Worker never cancels when I run the code because when I press this same button again after 5 minutes to run the worker, I got an errormessage that says that the worker is busy.


//The backgroundworker code

private: System::Void backgroundWorker1_DoWork(System::Object^  sender, System::ComponentModel::DoWorkEventArgs^  e) 
      for( int i = 0; i < 100000; i++;
7 Years
Discussion Span
Last Post by Lukezzz

It seems that I can break the loop and by this take actions in the backgroundWorker1_RunWorkerCompleted event.

This perheps is the correct procedure to do things when working with this component..
I haven´t understood the CancelWorkerAsync() yet. It doesn´t seem to work in a way...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.