Chapter 7. 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 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 to run multiple threads
  • Cancelling a parallel foreach loop
  • Catching errors in parallel foreach loops
  • Debugging multiple threads

Introduction

If you can find a single-core CPU in a computer today, it will probably mean that you are standing in a museum. Every new computer today utilizes the advantages of multiple cores. Programmers can take advantage of this extra processing power in their own applications. As applications have grown in size and complexity, in many cases they actually need to utilize multithreading.

While not every situation is always suited for the implementation of multithreaded code logic, it is good to know how to use multithreading to improve the performance of your applications. This chapter will take you through the fundamentals of this exciting technology in C# programming.

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

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