Whenever I talk about multithreading, asynchronous and parallel programming, someone asks about task cancellation; specifically, Windows Forms applications that support a Cancel button and a progress bar and perform the actual work separate from the UI thread so the application doesn't appear to hang. I can understand why this question comes up a lot.
While .NET contains a built-in component (the BackgroundWorker class) for performing this work, the documentation is not very clear. I've had the "pleasure" of implementing this pattern, and it's complex enough that I find myself doing a copy/paste from other projects to save myself the effort.
I'll walk you through the process of creating a simple form application with this functionality. You're more than welcome to skip ahead and grab the source code, which is distributed under the MIT Licence.
Read the full article on TechRepublic.





