This recipe describes another approach to asynchronous programming via an example of a BackgroundWorker
component. With the help of this object, we are able to organize our asynchronous code as a set of events and event handlers. You will learn how to use this component for asynchronous programming.
To step into this recipe, you will need Visual Studio 2015. There are no other prerequisites. The source code for this recipe can be found at BookSamples\Chapter3\Recipe7
.
To learn how to use the BackgroundWorker
component, perform the following steps:
Start Visual Studio 2015. Create a new C# console application project.
In the
Program.cs
file, add the followingusing
directives:using System; using System.ComponentModel; using static System.Console; using static System.Threading.Thread;
Add the following code snippet below the
Main
method:static void Worker_DoWork(object sender, DoWorkEventArgs e) { WriteLine($"DoWork thread pool...