Multithreading in Components
The BackgroundWorker component implements some of the threading features in the System.Threading namespace; the BackgroundWorker component is the easier way to implement multithreading functionality. For more information, see BackgroundWorker Component Overview.
Multithreading, or free threading, is the ability of an application to execute multiple threads of operation simultaneously. An example of a multithreaded application is a program that receives user input on one thread, performs a variety of complex calculations on a second thread, and updates a database on a third thread. In a single-threaded application, a user may spend idle time waiting for the calculations or database updates to finish. In a multithreaded application, these processes can proceed in the background so the user's time is not wasted.
Multithreading can be a powerful tool in component programming. By writing multithreaded components, you can create components that perform complex calculations in the background while leaving the user interface (UI) free to respond to user input.
Although multithreading can be a powerful tool, it can also be difficult to apply correctly. Improperly implemented multithreaded code can degrade application performance, or even cause frozen applications. The following topics introduce you to some of the considerations and best practices for multithreaded programming.
The .NET Framework offers several options for multithreading in components. The functionality in the System.Threading namespace is one option. The event-based asynchronous pattern is another. The BackgroundWorker component is an implementation of the asynchronous pattern; it gives you that advanced functionality encapsulated in a component for ease of use.