Chapter 9: Threading

Overview

Using multiple threads in a process is a common way of providing greater application responsiveness. On multiprocessor systems, extra threads (up to the number of processors) can increase performance by ensuring that all the processors are contributing simultaneously to the processing being carried out by the application. On single processor systems, extra threads will not improve performance. Too many threads on any system can decrease performance due to all the time the processor(s) spends thread-swapping), but multi-threading will improve responsiveness because the application can quickly swap from background processing to managing the user interface when the user does something. Using multiple threads also means that an application can carry on working while it is waiting for outside events, for example for data to be returned from an HTTP network request.

In this chapter, we'll have a detailed look at the extensive support that the .NET Framework offers for writing multi-threaded applications, and we'll go over several examples that illustrate how to code up a multi-threaded application, taking care of any issues with thread synchronization. In particular, we will cover:

  • The difference between operating system threads and managed threads

  • The relative benefits of the various available techniques for multi-threading

  • Invoking delegates asynchronously

  • Synchronizing data access using thread-synchronization objects such as mutexes, events, and so on

  • Timers

  • Explicitly creating worker threads

  • Terminating worker threads to ensure that thread data is cleaned up correctly



Advanced  .NET Programming
Advanced .NET Programming
ISBN: 1861006292
EAN: 2147483647
Year: 2002
Pages: 124

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net