Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2006

Tip: Looking for answers? Try searching our database.

Suspending a backgroundworker

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jakanapes - 03 May 2006 17:26 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.