Search, explore and find the perfect course for you

Parallel and Asynchronous Programming in C#

In recent years, parallel hardware has become the norm. It's not unusual to discover that one's smartphone has a multi-core CPU these days! At the same time, making calls to remote services has become common and users have come to expect highly responsive interfaces - both of which push developers towards asynchronous programming.

Thankfully, the .Net Framework and C# language have been evolving to help us cope with these new realities and expectations. Of course, there have always been threads and locks - but today, we've many, many more options: concurrent collections, parallel looping constructs, PLINQ, Tasks, the new async/await keywords in C# 5, the Reactive Extensions (Rx), the TPL Dataflow library with its Actor-based approach... Each of them are suitable for different problems. So how do you know what to use when, and how to use them effectively?

That's where this course comes in. It won't just teach you how to use all of these exciting new libraries. It will also help you to understand what kind of problem each one is aimed at, so that you can pick the appropriate solution to the challenges you face. It also provides clear explanations of pertinent theory and terminology, including a dive all the way down to the hardware level, so you'll have a strong grasp on what's really going on! Labs will provide an opportunity for you to try things out for yourself.

  • C# / .Net

Target audience

Experienced C# / .Net developers who need to learn about asynchronous and parallel programming.


Good knowledge of C#, especially generics, lambdas and LINQ. Previous experience of parallel or async programming is not required.

What you will learn

Day 1

Classifying Concurrency

  • Parallel vs. asynchronous
  • Task parallel vs. data parallel
  • CPU-bound vs. IO-bound
  • Shared vs. thread-local data
  • Blocking, lock-free, wait-free, and progress bounds

Understanding The Hardware

  • Why did CPUs go multi-core?
  • How CPU caches work with multi-core, and why it matters
  • Why thread-local storage helps
  • Why immutability helps
  • The problem of false sharing

Building Blocks

  • Threads
  • How many threads?
  • The thread pool
  • The Task abstraction


  • Monitors, the lock keyword
  • Multiple Reader, Single Writer locks
  • Deadlock
  • Lock granularity
  • The cost of locking
  • Avoiding locking

Concurrent Collections

  • What are the concurrent collections?
  • Concurrent queues, stacks, bags and dictionaries
  • The blocking collection
  • Queues and Staged Event Driven Architecture
  • Other use cases
  • Performance compared to locking the non-concurrent collections

The Parallel Class

  • Parallel for
  • Parallel foreach
  • Flow control in parallel loops
  • Keeping thread local state in parallel loops
  • Exceptions and parallel loops
  • Cancellation
  • Parallel invoke

Day 2

Asynchronous Programming

  • Why threads aren't ideal for blocking operations
  • ContinueWith and CPS (Continuation Passing Style)
  • Why CPS transforms hurt, and how async/await help
  • Exploring the new Async methods in .Net 4.5
  • Task combinators

More On Asynchrony

  • Understanding synchronization contexts
  • Cancellation
  • Task completion sources
  • Integrating asynchrony and parallelism

Introducing Rx

  • The Enumerable/Observable duality
  • IObserver and IObservable
  • Producing and consuming simple event streams
  • Subscription and unsubscription
  • Familiar Linq Operators, the Rx way
  • Converting enumerables to observables, and vice versa

Applying Rx

  • Using Rx with Windows Forms
  • Using Rx with WPF
  • Using Rx with async/await
  • Understanding schedulers
  • Writing tests for Rx code
  • Other useful Rx bits

Day 3

TPL DataFlow

  • Agents and actors: the ideas behind dataflow parallelism
  • Sources, targets and propagators
  • Transforming
  • Joining
  • Batching
  • Schedulers
  • Implementing custom blocks

Parallel LINQ

  • A quick LINQ refresher
  • Using PLINQ
  • Understanding how PLINQ parallelizes queries
  • Order (non-)preservation
  • Merge options
  • Cancellation
  • Dealing with exceptions
  • Custom aggregation functions

Atomic Operations and Lock-Free Data Structures

  • The Interlocked class
  • Basic atomic operations
  • Atomic Compare And Swap (CAS)
  • How to make any data structure lock free - at a cost
  • Livelock, and the contrast with wait freedom
  • The A-B problem

Putting It All Together

  • Mapping problems to suitable concurrent mechanisms
  • Integrating approaches
  • The importance of immutability
  • Trends so far, and how the future may look

Course info

Course code: T331
Duration: 3 days
Price: 25 970 SEK

Course schedule

31st Oct. - 2nd Nov. 2016 Book now
31st Oct. - 2nd Nov. 2016 Book now
1st - 3rd Nov. 2016 Book now
30th Nov. - 2nd Dec. 2016 Book now



Related courses

Contact us for details

+46 40 61 70 720

All prices excluding VAT