Write Asynchronous C# Code With Tasks and PLINQ
4.5 (103 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
1,387 students enrolled
Wishlisted Wishlist

Please confirm that you want to add Write Asynchronous C# Code With Tasks and PLINQ to your Wishlist.

Add to Wishlist

Write Asynchronous C# Code With Tasks and PLINQ

A comprehensive course teaching you how to write asynchronous C# code with the Task Parallel Library and PLINQ.
4.5 (103 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
1,387 students enrolled
Created by Mark Farragher
Last updated 4/2017
English
Current price: $10 Original price: $90 Discount: 89% off
5 hours left at this price!
30-Day Money-Back Guarantee
Includes:
  • 3 hours on-demand video
  • 2 Articles
  • 7 Supplemental Resources
  • 1 Coding exercise
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
What Will I Learn?
  • Learn how to write robust asynchronous C# code
  • Master the fundamentals of multi-threaded code
  • Learn how to use Threads
  • Learn how to use the Task class
  • Use a Task network to implement MapReduce
  • Parallelise any LINQ query with PLINQ
  • Learn the difference between Tasks and PLINQ
  • How to create Task continuations
  • ... and much more!
View Curriculum
Requirements
  • You need a Windows, Mac or Linux laptop with Microsoft Visual Studio, Xamarin Studio or Monodevelop
  • You should be a beginner, intermediate, or advanced C# developer
  • That's it!
Description

Last updated: March 08, 2017 - added a coding exercise.

BEST COURSE CHOICE for beginners and intermediate C# developers who want to learn about the Task Parallel Library and Parallel LINQ, and take their asynchronous programming skills to the next level.

Today we have beautiful libraries for writing multi-threaded C#, and there is simply no excuse for writing bad asynchronous code. In this course I will teach you how to write rock-solid code using Tasks and Parallel LINQ that works perfectly on your first try.

I wrote a multi-threaded conversion utility a year ago that successfully migrated 100,000 documents from SharePoint 2010 to SharePoint 2013. The program worked flawlessly the first time because I used PLINQ.

Sound good?

Writing multi-threaded code by hand is hard. I’ll prove it to you by showing you some code that exchanges data between two threads. You will be surprised how difficult it is to do this reliably.

But then I’ll show you how trivially easy it is to write asynchronous C# code using the Task Parallel Library and Parallel LINQ. These amazing frameworks allow anyone to write robust multi-threaded code that can take a beating.

By the end of the course you will be fluent in both the Tasks Parallel Library and Parallel LINQ.

Why should you take this course?

You should take this course if you are a beginner or intermediate C# developer and want to take your skills to the next level. Working with Tasks and Parallel LINQ might sound complicated, but all of my lectures are very easy to follow, and I explain all topics with clear code and many instructive diagrams. You'll have no trouble following along.

Or maybe you're working on a critical asynchronous section of C# code in a lage project, and need to make sure your code scales reliably over multiple CPU cores? The tips and tricks in this course will help you immensely.

Or maybe you're preparing for a C# related job interview? This course will give you an excellent foundation to answer any asynchronous programming questions they might throw at you.

30 day money-back guarantee

This course comes with an unconditional, Udemy backed, 30-day money-back guarantee. If you are dissatisfied with the course for any reason, simply request a refund and get your full purchase amount back, no questions asked.

Act now

This course today contains over 3 hours of video content. Enroll now to benefit from the current price and get free lifelong access to all future materials.

Who is the target audience?
  • Beginner, intermediate, and advanced C# programmers who want to learn about the Task Parallel Library and Parallel LINQ
  • Developers who are about to take a job interview and need to prepare for asynchronous code questions
  • Professionals who are writing a section of asynchronous code in a large C# project
Students Who Viewed This Course Also Viewed
Curriculum For This Course
28 Lectures
03:10:37
+
Introduction
5 Lectures 21:50

In this lecture I explain how this course is organised and I describe each of the upcoming sections in detail.

Preview 07:02

In this lecture I will tell a bit more about myself, my career, and my motivation to become an online trainer.

Preview 03:50

In this lecture we're going to look at the Task Parallel Library and PLINQ, and what they can do for you.

Preview 06:17

Many lectures in this course contain source code examples. Feel free to download the code and follow along. And here's the good news: it doesn't matter if you have a Window, Mac or Linux computer. The code will run on all three operating systems.

In this lecture I demonstrate how my solutions and projects run on all operating systems. I will show you how to build and run the source code on a Mac, on Linux and in Visual Studio running on Windows 8.

At the end of this lecture you will have learned that .NET code is portable and can run on at least five different operating systems.

Preview 03:19

Background Info - About Me
01:22
+
Multi-Threaded Code Fundamentals
7 Lectures 52:03

Welcome to the Multi-Threaded Code Fundamentals section. I will give a quick introduction on how the section is organized before we get started.

Section Introduction
01:53

In this lecture I will teach you how to start new threads using the System.Thread class: the workhorse of multi-threaded programming in C#.

I will also show you how you can give a descriptive name to a thread, to aid in debugging.

Finally, you will learn that there are two classes of threads: foreground- and background threads. I will show you the difference in behaviour between these two classes of threads.

How To Start A Thread
08:52

In this lecture I am going to show you the most common multi-threading programming problem: a race condition.

A race condition happens when 2 or more threads are trying to access and modify the same variable. I will demonstrate a race condition with a very simple program, with 2 threads accessing a shared integer class member.

Race Conditions
03:43

In this lecture I'll demonstrate how a special technique called 'thread locking' can resolve race conditions. I will show you several short examples of code prone to race conditions, and then I'll add thread locking to the code to fix the problem.

At the end of this lecture you will know exactly what thread locking is, how it resolves a race condition, and when you should implement it yourself.

Preview 07:55

In this lecture we are going to take a closer look at the lock statement in C#. You will learn that "lock" is in fact syntactic sugar for a pair of Monitor.Enter and Monitor.Exit calls. I will demonstrate several example programs using either the compact "lock" syntax, or the more verbose code that uses the Monitor class.

You will learn all the essentials of thread locking, including what code to lock, which synchronisation object to use, and what the advantages are of calling the Monitor class directly.

By the end of the lecture you will be proficient in thread locking, and you will be able to set up critical sections in your code with ease.

The Lock Statement
10:54

In this lecture I am going to take a look at thread synchronisation. The need for thread synchronisation arises when two or more threads need to exchange data in a controlled manner. I will show you a simple example program that attempts to exchange data between threads without any synchronisation, and you will see how the data transfer completely fails.

Next we will cover the workhorse of thread synchronisation: the AutoResetEvent. I will show you how you can line up two threads with a single AutoResetEvent variable, to ensure that you'll never lose any data. Then I'll show you how the single remaining race condition can be resolved by adding a second AutoResetEvent.

By the end of the lecture you will have a deep understanding of thread synchronisation: what it is, when you need it, and how you can implement it yourself.

Thread Synchronisation With AutoResetEvents
14:30

Congratulations on finishing this section. This is a recap of what we have learned.

Section Recap
04:16

Multi-Threaded Code Fundamentals
5 questions
+
Working With Tasks
8 Lectures 01:13:31

Welcome to the Working With Tasks section. I will give a quick introduction on how the section is organized before we get started.

Section Introduction
01:49

In the previous section you learned how to line up two threads with AutoResetEvents in order for them to exchange data. A reliable communication channel between two threads required two AutoResetEvents and a locked shared variable.

In this lecture I will show you how to implement the same channel using the Task class. You will learn that using tasks is much simpler than building the channel by hand.

Preview 11:57

In this lecture we're going to take a closer look at tasks. We have already encountered generic tasks that can return a value to another thread. This lecture will introduce non-generic tasks that run asynchronously in the background without returning any data. I'll show you how to start a non-generic task and wait for it to complete.

I'll also demonstrate how the .NET runtime uses a thread pool to execute tasks, and how you can fine-tune how threads are assigned to tasks. Finally we'll discover what happens when a task throws an exception.

Working With Tasks
12:19

In this lecture I will show you how to start a task with initialisation data. You will also learn how to cancel a running task by using a cancellation token.

Initialising And Cancelling Tasks
06:54

The nice thing about the Task Parallel Library is that you can connect together thousands of tasks into complex patterns. In this lecture you will learn how you can create hierarchies of parent and child tasks.

I will show you how to write a simple program that reverses the characters in each word using parent and child tasks.

Parent And Child Tasks
14:35

The Task Parallel Library lets you connect together thousands of tasks into complex patterns. In this lecture you will learn how you can create sequences of tasks with continuations. By combining task hierarchies with continuations you can implement any MapReduce problem in C#.

I will revisit the word reversing program from the previous lecture. I will use continuations and child tasks to rewrite the code as a MapReduce solution.

Task Continuations
12:37

There are three asynchronous libraries that you can use in C#: the Task Parallel Library, the Parallel class, and the Parallel LINQ library. Sometimes it can be difficult to choose between them.

In this lecture we are going to take a closer look at the pros and cons of the Task Parallel Library. By the end of the lecture you will know exactly when to use this Library.

When Should You Use Tasks?
08:10

Convert a sentence to pig latin
1 question

Congratulations on finishing this section. This is a recap of what we have learned.

Section Recap
05:10

Working With Tasks
6 questions
+
Using Parallel LINQ
6 Lectures 38:48
Welcome to the Parallel LINQ section. I will give a quick introduction on how the section is organized before we get started.


Section Intro
01:57

There are three asynchronous libraries that you can use in C#: the Task Parallel Library, the Parallel class, and the Parallel LINQ library. Sometimes it can be difficult to choose between them.

In this lecture we are going to take a closer look at the pros and cons of the Parallel LINQ library. By the end of the lecture you will know when to use this library.

When Should You Use PLINQ?
07:21

The Parallel LINQ library is ideal for implementing MapReduce operations. In the previous section we learned that my word reversal program can be expressed as a MapReduce problem and implemented with a combination of parent / child tasks and task continuations.

In this lecture I will revisit the program and reimplement it entirely in only a few lines of PLINQ code. By the end of the lecture you will have learned how to parallelise a LINQ query and fine-tune it for best performance.

Preview 12:00

In the previous lecture I showed you how to reimplement the word reversal program in PLINQ. But there was something wrong with the final result, when I used WithExecutionMode to force PLINQ to run the query on multiple threads.

In this lecture we are going to revisit those results, analyse what went wrong and attempt to fix the program to produce the correct output.

By the end of the lecture you will understand exactly how PLINQ affects item ordering.

PLINQ And Item Ordering
06:22

PLINQ is an extremely powerful library. It valiantly attempts to parallelise every LINQ query you throw at it but sometimes it simply cannot execute a query on multiple threads.

When a query is too complex PLINQ will silently fall back to sequential mode and execute the entire query on a single thread. When this happens PLINQ will actually be slightly slower than regular LINQ!

In this lecture we will identify all the scenarios in which PLINQ falls back to sequential mode. By the end of the lecture you will know which queries should not be parallelised.

Limitations Of PLINQ
06:44

Congratulations on finishing this section. This is a recap of what we have learned.

Section Recap
04:24

Using Parallel LINQ
4 questions
+
Final Words
2 Lectures 04:49

In this lecture I would like to thank you for finishing the course and offer some final words.

Course Recap
02:57

Check out my promotional discounts and freebies here. 

Bonus Lecture
01:52
About the Instructor
Mark Farragher
4.4 Average rating
1,180 Reviews
6,939 Students
11 Courses
Microsoft Certified Trainer - 1000+ reviews, 4.4 rating

My IT career spans 2 decades and I've worn many different hats over the years. I am a serial entrepreneur and have launched two startups in The Netherlands. 

I started using C# and the .NET framework 15 years ago. Today I live in Barcelona and spend my time creating online courses to share my knowledge of professional C# programming with a wide audience.

I have active MCSA and MCSD certifications plus legacy MCAD and MCT certifications. You can verify my credentials on my LinkedIn profile. 

Feel free to check out my course ratings before enrolling. As of today I have 10 published courses, 900+ reviews, and a recent average course rating of 4.5.