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 REQUIREDC# coding

MULTITHREADED PROGRAMMING AT A GLANCE

Thread Basics185  
 Understanding the Key Thread Properties and Methods185Terminating a Thread188
Suspending a Thread191
 Explaining the ThreadStart Delegate187Creating a Pause by “Sleeping” a Thread191
 Creating a Thread188Joining a Thread191
 Running a Thread188  
Synchronization192  
 Understanding the Different Types of Synchronization193  
Applying the lock Keyword193  
 Raising Thread Events194Safeguarding Variables (Interlocked Increment/Decrement)203
 Using the Mutex Class196
 Using the Monitor Class198Reading Without Waiting (ReaderWriterLock)203
Using the Thread Pool for Asynchronous Programming206  
 Explaining the WaitCallback Delegate206Queuing a Work Item207
 Passing Data to Threads208
Further Reading209  

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.197.251