C# Concurrent Collections

Learn how to use concurrent collections in multithreaded code! This course will teach you the correct use of ConcurrentDictionary, as well as introducing you to producer-consumer scenarios and the blocking collection.
Course info
Rating
(557)
Level
Advanced
Updated
May 15, 2015
Duration
3h 32m
Table of contents
Introducing the Concurrent Collections
Introducing ConcurrentDictionary
Concurrent Dictionary Demo
The Producer-Consumer Collections: Queues, Stacks and Bags
Producer-consumer and BlockingCollection Demo
Some Concurrent Collections Best Practices
Description
Course info
Rating
(557)
Level
Advanced
Updated
May 15, 2015
Duration
3h 32m
Description

Learn how to use concurrent collections in multithreaded code! This course is a comprehensive introduction to the concurrent collections. It shows you how to use each of the main collection types: ConcurrentDictionary, ConcurrentQueue, ConcurrentBag, and ConcurrentStack. You'll learn the correct techniques for using these collections to avoid bugs such as race conditions, and also how to use BlockingCollection with the concurrent collections correctly in producer-consumer scenarios. The course rounds off with a look at some concurrent collection best practices.

About the author
About the author

Simon is a senior developer with over 20 years programming experience, particularly covering C++ and the .NET Framework. He believes knowledge is to be shared and has written or co-written more than a dozen books for professional programmers.

More from the author
Beginning C# Collections
Beginner
3h 26m
Mar 29, 2019
C# Equality and Comparisons
Intermediate
4h 51m
Sep 10, 2014
More courses by Simon Robinson
Section Introduction Transcripts
Section Introduction Transcripts

Introducing the Concurrent Collections
Hello. I'm Simon Robinson welcoming you to this Pluralsight course, C# Concurrent Collections. The concurrent collections are a new set of collection types that Microsoft introduced for. NET 4, which is specifically designed to be used in a multi-threaded environment. The aim of this course is to teach you how to use the concurrent collections safely and correctly and this looks like the course all ready to open, let's look inside. In the box we have the course modules. I've arranged them to show how they depend on each other. This first module is a general overview. I'll mention the purposes of the different types available in the system. collections. concurrent namespace and clarify in what ways concurrent collections can and can't help in a multi-threaded environment. In particular, you will learn the importance of the ConcurrentDictionary as the main general purpose concurrent collection. My teaching style, by the way, is very much that I like to make sure we've covered the concepts adequately and then apply them, which means there's a fair bit of theoretical learning in this first module, and then much more actual coding as we work through the course. The next two modules will go into ConcurrentDictionary in some detail. In module two I'll show you what methods it provides and how it differs from the standard generic dictionary using very simple code. Then in module three we will apply this knowledge using ConcurrentDictionary in a much more realistic, multi-threaded demo. Then we do basically the same thing for a group of collections that I personally like to call the Producer-Consumer collections, concurrent queue, concurrent stack, and concurrent bag. Again, there are two modules, module four introduces these tops, and then module five shows a more realistic demo, which also brings in the BlockingCollection, and we will wind up in the last module with a look at some best practices. Here you will learn a few tips on using concurrent collections effectively and learn how to avoid some common pitfalls, especially related to performance. Now before we begin I just need to mention a couple of prerequisites for the course. Firstly, this course is about concurrent collections, it's not a general threading or thread safety course. I will draw attention to particular points of thread safety and thread synchronization that relate to concurrent collections, but in general I'm assuming you know what a thread is, and you're comfortable, for example, using. NET tasks to do parallel processing. If you find while you're watching this course that you do need a refresher in the threads and tasks I can recommend Joe Hummel's Pluralsight course, Introduction to Async and Parallel Programming in. NET 4. Also, and just as important, I'm assuming you know how to use the standard generic collections, which roughly means the ones in the system. collections. generic namespace. My previous course, C# Collections Fundamentals covers the standard collections, and this concurrent collections course that you're watching now is largely a direct follow on from that course, so if you feel you need a refresher in standard collections do check that out. As far as code goes, I'm using Visual Studio 2013 and. NET 4. 5 for all the demos. Concurrent collections were actually released with. NET 4. 0, so if you're using. net4. 0 and Visual Studio 2010 you should still be able to use the concurrent collections. Bear in mind though that there were originally some performance issues with concurrent back in 4. 0, those were fixed in. NET 4. 5 and are no longer an issue.