O'Reilly logo

C# 2008 and 2005 Threaded Programming: Beginner's Guide by Gastón C. Hillar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - Creating safe counters using delegates and avoiding concurrency problems

The quality assurance team discovered another bug in the renewed encryption dispatcher. It displays a very nice counter image, but is not updated as the files are being encrypted. They want you to change the application to add an encrypted files counter and to increase it exactly when each work item is completed.

Again, that sounds easy for a BackgroundWorker component, but this time, you cannot use it because you would have to introduce a loop in the BackgroundWorker thread to collect the results. Instead, you can take advantage of the delegate invocation from the worker thread to update the user interface safely and increase the counter.

Now, we are going ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required