Creating a better BackgroundWorker: CancelImmediately and other goodies

This blog has moved to http://osherove.com/blog
Published Wednesday, November 9, 2005 1:06 PM by RoyOsherove
Filed under:

Comments

Wednesday, November 9, 2005 3:57 PM by Oskar Austegard

# re: Creating a better BackgroundWorker: CancelImmediately and other goodies

I'm still stuck in 1.1 - so: from what you could tell, is the final BackgroundWorker component any different from the one Juval created?

One of the challenges involved with using the BWC is the non-typed nature of the e.Argument. I ended up writing a CodeSmith template to bundle my method parameters into a class to simplify the process...
Wednesday, November 9, 2005 5:40 PM by Roy Osherove

# re: Creating a better BackgroundWorker: CancelImmediately and other goodies

Oskar: The final component is not exactly the same but it works the same as the one in 1.1. The one Juval wrote was based in design on the final one that was released in 2005.
The final one employs .NET 2.0 specific classes such as AsyncOperation to do its bidding which was not possible in 1.1.

They could have used generics to help with the untyped natire of the e argument, but they somehow chose not to...
Wednesday, November 9, 2005 6:40 PM by Oskar Austegard

# re: Creating a better BackgroundWorker: CancelImmediately and other goodies

But the interface is the same? Method/Event names, etc?
Monday, December 5, 2005 1:15 PM by Denise Phillips

# re: Creating a better BackgroundWorker: CancelImmediately and other goodies

Do you have any unit testing examples working with these classes?
Friday, July 21, 2006 6:43 PM by Earl Damron

# re: Creating a better BackgroundWorker: CancelImmediately and other goodies

I think I am misunderstanding something. :-) I was hoping the BackgroundWorkerEx.StopImmediately would stop immediately, but it doesn't. This code always fails: if (bwEx.IsBusy) { Debug.WriteLine("Calling StopImmediately()"); bwEx.StopImmediately(); Debug.WriteLine("StopImmediately() returned"); } bwEx.RunWorkerAsync(loadState); Despite getting both messages in the immediate window, I still get a InvalidOperationException("BackgroundWorker_WorkerAlreadyRunning") when I call bwEx.RunWorkerAsync(...). Do I misunderstand what this component is for or how to use it? Thanks
Friday, July 21, 2006 7:37 PM by RoyOsherove

# re: Creating a better BackgroundWorker: CancelImmediately and other goodies

Calling them immediately one after the other may produce this problem due to a resource locking problem.

Calling thread.sleep(1) inside the "RunWorkerAsync" method as the first line shoudl solve it..