By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,920 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

Suspending a backgroundworker

P: n/a
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?

May 3 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Well, I tried using the cancelling functions of background worker and
it ALMOST works...

When the user presses pause, it calls this, of course:


and in my function:

while( true )
if( worker->CancellationPending )
e->Cancel = true;
//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

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

Any ideas?

May 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.