C# Concurrent Collections

Learn to use concurrent collections effectively to store data in a multithreaded environment, keeping the code efficient and avoiding data corruption and race conditions.
Course info
Level
Advanced
Updated
Jul 31, 2020
Duration
2h 42m
Table of contents
Course Overview
Collections and Atomic Operations
From Dictionary to ConcurrentDictionary
ConcurrentDictionary: Avoiding Race Conditions
The Producer-consumer Collections: Queues, Stacks, and Bags
Avoiding Polling with the BlockingCollection
Good and Bad Coding Practices with Concurrent Collections
Enumerating Concurrent Collections
Description
Course info
Level
Advanced
Updated
Jul 31, 2020
Duration
2h 42m
Description

Making applications concurrent can be a vital part of ensuring good responsiveness and high performance, but standard collections are not designed for concurrent environments. In this course, C# Concurrent Collections, you’ll learn how to use concurrent collections to bring the power of manipulating data in collections to multithreaded scenarios by thinking about problems in a concurrent way. First, you’ll discover how to avoid race conditions and data corruption, and how to use lambdas and closures to complete concurrent collection operations in a thread-safe way. Next, you’ll explore producer-consumer collections, such as stacks and queues. Then, you'll learn how to safely consume all items from a queue when you don’t know if other threads might be adding other items. Finally, you’ll delve into good coding practices to keep your concurrent collection code efficient. By the end of this course, you’ll understand how to safely store data in collections and have multiple threads access that data concurrently, while avoiding the thread synchronization bugs that can otherwise plague concurrent code.

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
Advanced C# Collections
Intermediate
3h 46m
Jan 9, 2020
Beginning C# Collections
Beginner
3h 25m
Mar 29, 2019
More courses by Simon Robinson
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi, everyone. I'm Simon Robinson, and welcome to C# Concurrent Collections. And let me tell you, collections are amazing, and having apps work asynchronously is amazing, and when you put the two together, you have the power to truly manipulate data in a way that makes full use of the CPU to give you a highly responsive, efficient, multitasking app. That's what concurrent collections can offer you. But if you don't understand how to use concurrence collections properly, it's surprisingly easy to corrupt your data through thread‑synchronization bugs. Merely being able to launch async tasks isn't enough if you have data shared between different threads. You also have to learn to think about your logic in a concurrent way, so you can anticipate and avoid threads corrupting each other's data. And that's exactly what I teach in this course. You'll learn all about how to read and updates data in a concurrence dictionary in a thread‑safe way, and along the way, you'll learn how atomic methods can help keep your data safe and how race conditions can destroy that safety if you're not careful. Then I'll show you how to use producer‑consumer collections, stacks, and queues, and bags to safely generate items to be processed, and then have other threads process those items, just like complex enterprise apps, such as web servers and database servers have to do all the time. By the end of this course, you'll be able to use concurrence collections to create efficient code that safely allows multiple threads to simultaneously access and manipulate data in collections.