C# Multithreaded Parallel Programming
| This tutorial—CSharp Multithreaded Parallel Programming—is from Multithreaded Parallel Programming, by Andrew Troelsen. Copyright © 2010 Andrew Troelsen. All rights reserved. This article is reproduced by permission. This tutorial has been edited especially for C# Online.NET. Read the book review! |
|
These days it is quite common for new computers to make use of multicore processors (or at very least a
hyperthreaded single-core processor). Without making use of multiple threads, developers are unable to exploit
the full power of multicore machines.
Multithreaded and Parallel Programming in C#
Nobody enjoys working with an application which is slow and sluggish during its execution. Moreover, nobody enjoys starting a task in an application (perhaps initiated by the clicking of a toolbar item) which prevents other parts of the program from being as responsive as possible. Before the release of .NET, building applications that had the ability to perform multiple tasks required authoring very complex C++ code and the Windows threading APIs. Thankfully, the .NET platform provides a number of ways for you to build software which can perform complex operations on unique paths of execution, with far less fuss and bother.
This chapter begins by revisiting the .NET delegate type to investigate its intrinsic support for asynchronous method invocations. As you’ll see, this technique allows you to invoke a method on a secondary thread of execution without needing to manually create or configure the thread itself.
Next, you’ll be introduced to the System.Threading namespace. Here you’ll examine numerous
types (Thread, ThreadStart, etc.) that allow you to easily create additional threads of execution. As well,
you will learn about various synchronization primitives that the .NET Framework provides, which helps
ensure that multiple threads can share data in a non-volatile manner.
The final part of this chapter will examine the brand new .NET 4.0 Task Parallel Library (TPL) and PLINQ (Parallel LINQ). Using these APIs, you can program against a set of higher level types, which do a good deal to manage thread details on your behalf.
|


