Team LiB
Previous Section Next Section

Chapter 9. Multithreaded Programming

IN BRIEF

This chapter illustrates the benefits of multithreaded programming, as well as the technical details involved in using threads in your applications. The first section talks about the basics of multithreaded programming. You will learn how to create, pause, join, stop, and terminate threads. Next, the chapter illustrates thread synchronization in depth. You will learn why you need to synchronize threads and the various methods of doing so. Finally, you will see examples of the use of the thread pool class. You will learn how to create worker threads and post work items to a thread pool.

WHAT YOU NEED

RECOMMENDED SOFTWARE

.NET Framework

C#.NET environment

RECOMMENDED HARDWARE

.NET-enabled desktop client

SKILLS REQUIRED

C# coding


MULTITHREADED PROGRAMMING AT A GLANCE

Thread Basics

185

  
 

Understanding the Key Thread Properties and Methods

185

Terminating a Thread

188

Suspending a Thread

191

 

Explaining the ThreadStart Delegate

187

Creating a Pause by "Sleeping" a Thread

191

 

Creating a Thread

188

Joining a Thread

191

 

Running a Thread

188

  

Synchronization

192

  
 

Understanding the Different Types of Synchronization

193

  

Applying the lock Keyword

193

  
 

Raising Thread Events

194

Safeguarding Variables (Interlocked Increment/Decrement)

203

 

Using the Mutex Class

196

 

Using the Monitor Class

198

Reading Without Waiting (ReaderWriterLock)

203

Using the Thread Pool for Asynchronous Programming

206

  
 

Explaining the WaitCallback Delegate

206

Queuing a Work Item

207

 

Passing Data to Threads

208

Further Reading

209

  


    Team LiB
    Previous Section Next Section