Have you ever built an application where users had to wait while the application performed some lengthy calculation or operation? Learn how to improve your application's responsiveness by creating and controlling threads.
by Peter G. Aitken
Oct 21, 2002
Page 3 of 3
Using the ThreadPool class for new threads is quite easy, as you have seen; however you may need more control over the threads you create. For example, you may need to assign a priority to a thread, to pause and restart the thread, or to stop it before it has completed. You may also need to synchronize threads, as discussed earlier, to prevent conflicts when accessing resources. When you need this level of control you must use the Thread class. Each instance of the Thread class represents a separate thread. The class members let you set the thread's priority, start, pause, and stop it, and also determine its current state. The details of using the Thread class are beyond the scope of this article, but you can find complete details as well as demonstration programs in the .NET Framework documentation.
Windows is a preemptive multitasking operating system, giving it the ability to appear to perform multiple tasks simultaneously. The basic unit for multitasking is the thread. A process, or program, typically has only a single thread. In some situations it can be advantageous for a program to have two or more threads executing at once, a technique called multithreading. In particular, multithreading can greatly improve a program's responsiveness to the user while time-consuming calculations or I/O tasks are being performed. The .NET Framework makes the implementation of multithreading relatively easy, and while multithreading is not a cure-all for performance problems it is definitely a tool that every programmer should have in his or her toolbox.
Peter G. Aitken has been writing about computers and programming for over 10 years, with some 30 books and hundreds of articles to his credit. Recent book titles include Developing Office Solutions With Office 2000 Components and VBA, Windows Script Host, and the soon to be published XML the Microsoft Way. He is a regular contributor to OfficePro magazine, and for several years was a contributing editor for Visual Developer Magazine where he wrote the popular Visual Basic column. Peter is the proprietor of PGA Consulting, providing custom application and Internet development to business, academia, and government since 1994. You can reach him at