High Performance Programming Using Parallel and Multithreading in C#

This chapter takes a look at improving your code's performance using multithreading and parallel programming. In this chapter, we will cover the following recipes:

  • Creating and aborting a low-priority background thread
  • Increasing the maximum thread pool size
  • Creating multiple threads
  • Locking one thread until the contended resources are available
  • Invoking parallel calls to methods using Parallel.Invoke
  • Using a parallel foreach loop
  • Cancelling a parallel foreach loop
  • Catching errors in parallel foreach loops
  • Debugging multiple threads

Get C# 7 and .NET Core Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.