Avatar of Stephen Forero
Stephen Forero
Flag for United States of America asked on

backgroundworker.cancelasync always busy

hello all,

I have a wpf project, and on the timeconsuming processing, I run the method on a background worker.  like so

        public InternalLoginClass()
        {
                                    if (!backgroundWorkerTimeline.IsBusy)
                                    {
                                        object[] tempArguments = new object[3];
                                        tempArguments[0] = connString;
                                        tempArguments[1] = "FULL";
                                        tempArguments[2] = clientID;
                                        backgroundWorkerTimeline.RunWorkerAsync(tempArguments);
                                    }
}

Open in new window


then when user hits button I run

            //check for background workers to complete
            if (myInternalLoginClass.backgroundWorkerTimeline.IsBusy) myInternalLoginClass.backgroundWorkerTimeline.CancelAsync();
            while (myInternalLoginClass.backgroundWorkerTimeline.IsBusy)
            {
            }
***next line of code here

Open in new window


I was thinking that as long as I put in that continuous loop, while busy... do nothing,
the backgroundthread would run until finished, then since it was complete, it would hit ***next line of code here.

but when I try this the loop never exits... the workers stays in IsBusy.

Am I thinking about this the wrong way?  Even when I hit cancelasync and check in the background thread... it stays ISBUSY?

any ideas?
C#.NET Programming

Avatar of undefined
Last Comment
Stephen Forero

8/22/2022 - Mon
SOLUTION
ktaczala

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Jacques Bourgeois (James Burger)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Naman Goel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Stephen Forero

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Stephen Forero

ASKER
added details in my response for solution
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck