Is it possible to suspend the background worker without cancelling it
or letting it finish and restarting?
My application runs in a loop and I'd like to have a pause button, but
I'm having trouble getting it to work.
I tried to create a loop based on a variable that gets set to false
when pause is pressed so the worker will finish working, and then call
the backgroundWorker1->RunWorkerAsync() again, but this doesn't seem to
work. I check the IsBusy flag, but my app locks up.
Any ideas?
Jakanapes - 03 May 2006 19:18 GMT
Well, I tried using the cancelling functions of background worker and
it ALMOST works...
When the user presses pause, it calls this, of course:
backgroundWorker1->CancelAsync();
and in my function:
while( true )
{
if( worker->CancellationPending )
{
e->Cancel = true;
break;
}
else
{
//some stuff
worker->ReportProgress( 100, (System::Object^)%output );
}
It'll stop just fine when pause is pressed, but when start is pressed
again( calling backgroundWorker1->RunWorkerAsync(); ) the program
freezes.
If I remove the while( true) and brackets from the function, I can call
it multiple times from the start button.
And if I remove the worker->ReportProgress call from the loop, I can
press pause and start multiple times without freezing the app. I know
it's not the code in backgroundWorker1_ProgressChanged because I've
commented that out and it still froze when worker->ReportProgress was
called.
Any ideas?