Threading in C#

An extensive online book on multithreading in C#. This tackles difficult issues such as thread safety, when to use Abort, Wait Handles vs Wait and Pulse, the implications of Apartment Threading in Windows Forms, using Thread Pooling, Synchronization Contexts, Memory Barriers and non-blocking synchronization constructs.


C# supports parallel execution of code through multithreading. A thread is an independent execution path, able to run simultaneously with other threads.

A C# client program (Console, WPF, or Windows Forms) starts in a single thread created automatically by the CLR and operating system (the “main” thread), and is made multithreaded by creating additional threads.

Table of Contents

  • Introduction and Concepts
  • Creating and Starting Threads
  • Thread Pooling
  • Synchronization Essentials
  • Locking
  • Thread Safety
  • Event Wait Handles
  • Synchronization Contexts
  • Event-Based Asynch Pattern
  • BackgroundWorker
  • Interrupt and Abort
  • Safe Cancellation
  • Lazy Initialization
  • Thread-Local Storage
  • Timers
  • Nonblocking Synchronization
  • Signaling with Wait and Pulse
  • The Barrier Class
  • Reader/Writer Locks
  • Suspend and Resume
  • Aborting Threads
  • Parallel Programming
  • Why PFX?
  • The Parallel Class
  • Task Parallelism
  • Working with AggregateException
  • Concurrent Collections
  • SpinLock and SpinWait

Book Details

Author(s): Joseph Albahari
Format(s): PDF, HTML
File size: 1.16 MB
Number of pages: 125
Link: Download or read online.

Leave a Reply