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:
backgroundWorker1->CancelWorkerAsync();
...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 !
backgroundWorker1->RunWorkerAsync();
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.
backgroundWorker1->CancelWorkerAsync();
//The backgroundworker code
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e)
{
for( int i = 0; i < 100000; i++;
{
Thread::Sleep(10000);
}
}