Chapter 1. Threading Basics

In this chapter, we will cover the basic tasks to work with threads in C#. You will learn the following recipes:

  • Creating a thread in C#
  • Pausing a thread
  • Making a thread wait
  • Aborting a thread
  • Determining a thread state
  • Thread priority
  • Foreground and background threads
  • Passing parameters to a thread
  • Locking with a C# lock keyword
  • Locking with a Monitor construct
  • Handling exceptions

Introduction

At some point of time in the past, the common computer had only one computing unit and could not execute several computing tasks simultaneously. However, operating systems could already work with multiple programs simultaneously, implementing the concept of multitasking. To prevent the possibility of one program taking control of the CPU ...

Get Multithreading with C# Cookbook - Second Edition 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.