C# Multithreaded and Parallel Programming

Develop powerful C# applications to take advantage of today's multicore hardware

Posted by Box XV on April 27, 2020. 5 min read.

C# Multithreaded and Parallel Programming

✅ Publisher: Packt Publishing

✅ Year: December 24, 2014

✅ Authors: Rodney Ringler

✅ Language: English

✅ Pages: 346

✅ Size: 27.7 MB

✅ Download source code: 9781849688321_code.zip


Learn

  • Explore all the essential methods used for programming multithreaded applications
  • Enhance the performance of an application by designing various parallel operations to achieve concurrency
  • Build powerful applications using the Task Parallel Library (TPL), which makes concurrent processing of items in a data collection simple
  • Implement data parallelism using the Parallel library, concurrent collections, and PLINQ
  • Debug your multithreaded applications using the Threads view, Tasks window, Parallel Stacks window, and Parallel Watch window
  • Accomplish any given parallel task using two of the most popular parallel patterns for development: Pipelining and producer-consumer
  • Get to grips with the Asynchronous Programming Model (APM) to learn to begin and end asynchronous operations

About

Most modern machines have dual-core processors. This means that the present-day computer has the ability to multitask. Using multiple cores means your applications can process data faster and be more responsive to users. However, to fully exploit this in your applications, you need to write multithreading code.

We will begin by covering some techniques that have been around since the beginning of .NET, including the BackgroundWorker component, timers, and the Thread class. We will use tasks, task factories, and parallel loops to develop multithreaded applications at a higher level than directly creating and managing individual threads. Finally, we will look at the tools Visual Studio provides for debugging parallel applications, common concurrent design patterns, and the latest updates in PLINQ and async.

Features

  • Make use of the latest Visual Studio debugging tools, to manage and debug multiple threads running simultaneously
  • Learn how to use the Thread, Task, and Parallel libraries in your C# applications
  • Explore the evolution of multithreaded development in C#, starting with BackgroundWorker classes and moving on to threads and tasks and finally covering Async

Table of contents

Chapter 1: Understanding Multiprocessing and Multiple Cores

1.1 Mono-processor systems – the old gladiators

  • Single core – only one warrior to fight against everybody
  • Doing a tiny bit of each task

1.2 Multiprocessor systems – many warriors to win a battle

1.3 Multiple core processors and hyperthreading

  • Taking advantage of multiple execution cores

1.4 Examining our hardware

1.5 OS scheduler operations

1.6 Designing for concurrency

  • Estimating performance improvements
  • Amdahl’s law
  • Gustafson’s law

1.7 Summary


Chapter 2: Looking at Multithreaded Classes – BackgroundWorker

2.1 Getting started with the BackgroundWorker component

2.2 Simple example without a BackgroundWorker object

  • How to do it
  • How does it work?

2.3 WPF example with an asynchronous BackgroundWorker

  • How to do it
  • How does it work?
  • How does it work without blocking the UI?
  • How to do it
  • How does it work?

2.4 WPF example with an synchronous BackgroundWorker

2.5 Showing progress

  • How to do it
  • How does it work?

2.6 Canceling a BackgroundWorker thread

  • How to do it
  • How does it work?

2.7 Working with multiple BackgroundWorker components

  • How does it work?
  • How does it work?

2.8 Exploring other examples

2.9 Summary


Chapter 3: Thread Class – Heavyweight Concurrency in C#

3.1 Creating threads with the Thread class

  • Let’s get started with an encryption program
  • How to do it
  • How it works

3.2 Creating an application with threads

  • How to do it
  • How it works

3.3 Sharing data between threads

  • How to do it
  • How it works

3.4 Passing parameters to threads

  • How to do it
  • How it works
  • Have a go hero – concurrent UI feedback

3.5 Summary


Chapter 4: Advanced Thread Processing

4.1 Pipelining

  • Explaining pipelining using an image processing application
  • How to do it
  • How it works
  • Understanding the pixels’ color compositions

4.2 Pausing and restarting threads

  • How to do it
  • How it works

4.3 Signals between threads

  • How to do it
  • How it works
  • Using the AutoResetEvent class to handle signals between threads
  • Using the WaitHandle class to check for signals

4.4 Joining threads

  • How to do it
  • How it works

4.5 Locking resources to ensure thread-safe data

  • How to do it
  • How it works

4.6 Error handling with threads

  • How to do it
  • How it works

4.7 Summary


Chapter 5: Lightweight Concurrency – Task Parallel Library (TPL)

5.1 Task Parallel Library

5.2 Exploring tasks

  • How to do it
  • How it works

5.3 Tasks with return values

  • How to do it
  • How it works

5.4 Concurrent collections

  • How to do it
  • How it works

5.5 Exploring the TaskFactory class

  • How to do it
  • How it works

5.6 Task schedulers

5.7 Introducing the Parallel class

  • How to do it
  • How it works

5.8 Delegates and lambda expressions

5.9 Summary


Chapter 6: Task-based Parallelism

6.1 Waiting for a task to complete

  • How to do it
  • How it works

6.2 Waiting for multiple tasks to complete

  • How to do it
  • How it works

6.3 Canceling a task

  • How to do it
  • How it works

6.4 Task exception handling

6.5 Summary


Chapter 7: Data Parallelism

7.1 Parallel loop processing

  • How to do it
  • How it works

7.2 Data parallelism on collections using Parallel.ForEach

  • How to do it
  • How it works

7.3 Canceling a parallel loop

  • How to do it
  • How it works

7.4 Handling exceptions in parallel loops

  • How to do it
  • How it works

7.5 Using thread-local variables in parallel loops

  • How to do it
  • How it works

7.6 Summary


Chapter 8: Debugging Multithreaded Applications with Visual Studio

8.1 Considerations for debugging multithreaded applications

8.2 Using the Threads window

8.3 Using the Tasks window

8.4 Using the Parallel Stacks window

8.5 Using the Parallel Watch window

8.6 Debugging an entire application

  • How to do it
  • How it works

8.7 Summary


Chapter 9: Pipeline and Producer-consumer Design Patterns

9.1 Pipeline design pattern

  • How to do it
  • How it works

9.2 Explaining message blocks

  • BufferBlock
  • ActionBlock

9.3 Producer-consumer design pattern

  • How to do it
  • How it works

9.4 Summary


Chapter 10: Parallel LINQ – PLINQ

10.1 Executing a PLINQ

  • How to do it
  • How it works

10.2 Ordering in PLINQ

  • How to do it
  • How it works

10.3 Merging in PLINQ

  • How to do it
  • How it works

10.4 Canceling a PLINQ

  • How to do it
  • How it works

10.5 Understanding performance improvements in PLINQ

10.6 Summary


Chapter 11: The Asynchronous Programming Model

11.1 Introduction to the Asynchronous Programming Model

  • How to do it
  • How it works

11.2 Using an AsyncCallback delegate method

  • How to do it
  • How it works

11.3 The async and await keywords

  • How to do it
  • How it works

11.4 Summary


https://www.packtpub.com/application-development/c-multithreaded-and-parallel-programming
https://www.amazon.com/Multithreaded-Parallel-Programming-Rodney-Ringler-ebook/dp/B00RP13BKS/