Advanced .NET Programming

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:

Категории