First Technology Transfer

Standard and Advanced Technical Training, Consultancy and Mentoring

Course CSH103 - C# .Net Threads Programming

Duration: 3 Days

Intended Audience

The course is aimed at programmers who already know C# and who wish to gain a deeper understanding of mutli-tasking and multi-threading in the context of developing .NET applications.


Microsoft 32bit and 64bit operating systems use threads as the unit of scheduling. Threads associated with a given task share resources and hence inter-thread communication by use of shared memory is quite efficient. Multithreading is well suited to implementing scaleable server tasks running on Symmetric Multi-Processor (SMP) architectures, as the processors share the same memory. Since threads share the same executable code multiple threads can run on separate processors and make use of the same virtual memory space. The code generated by the compiler is the same whether it will run on a single or multi-core SMP processor. Multithreading can also be used to run I/O processing in a separate thread to e.g. data processing.

This module will cover multi-threading programming using C# and .NET multi-threading support. Multi-tasking in the context of .NET will also be covered. A lot of attention will be paid to interthread communication both for synchronisation and for safe access to shared resources.


  • Multi-threading and Multi-tasking in Windows
    • Symmetric MultiProcessor (SMP) Architectures
    • WinAPI and the separation between user space and kernel space code
    • How the .NET framework fits in with the WinAPI
    • Multi-threading and Multi-tasking in the Windows world
  • Threads - Creation, Manipulation and Management
    • Creating threads - the Thread class
    • Implied type declaration
    • Runnable Interface
    • Thread priorities
    • Stopping and Aborting threads
    • Thread join
    • Threadpools
    • Thread termination
    • Graceful shutdown
  • Synchronisation and control of access to shared resources
    • Mutex
    • Semaphore
    • Event object - ManualResetEvent and AutoResetEvent
    • Memory mapped files
    • Stopping and Aborting threads
    • Thread join
    • Threadpools
    • Interlocked interface
    • Increment
    • Exchange
  • Implementing Classical Multi-threading Examples in C# and .NET
    • Producer-consumer example
    • Readers and Writers Example
    • Dining Philosopher's Example
    • Workcrew Example
    • Stopping and Aborting threads
    • Thread join
    • Threadpools
  • Timing and Timers
    • Sleep
    • Timer
    • Implementing Timer callbacks
    • Thread interrupts
  • Parallel Programming and Threads
    • Overview of the PFX Parallel Framework
    • The Parallel class
    • Parallel LINQ (PLINQ)
    • Task parallelism
    • Concurrent collections
    • SpinLock and SpinWait