C# allows you to execute code in parallel through multithreading.
A thread is analogous to the operating system process in which your application runs. Just as processes run in parallel on a computer, threads run in parallel within a single process. Processes are fully isolated from each other; threads have just a limited degree of isolation. In particular, threads share (heap) memory with other threads running in the same application. This, in part, is why threading is useful: one thread can fetch data in the background, for instance, while another thread can display the data as it arrives.
This chapter describes the language and Framework features for
creating, configuring, and communicating with threads, and how to
coordinate their actions through locking and signaling. It also covers the
basic predefined types that assist threading, such as
BackgroundWorker and the
Multithreading has many uses; here are the most common:
By running time-consuming tasks on a parallel “worker” thread, the main UI thread is free to continue processing keyboard and mouse events.
Multithreading is useful when a thread is awaiting a response from another computer or piece of hardware. While one thread is blocked while performing the task, other threads can take advantage of the otherwise unburdened computer.
Code that performs intensive ...