Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

LinkedIn Learning

Advanced C#: Thread-Safe Data with Concurrent Collections

via LinkedIn Learning

Overview

Learn how to work with the thread-safe concurrent collections to share data across threads and build scalable applications.

Syllabus

Introduction
  • Thread-safe data with concurrent collections
  • What you should know
  • How to access the sample code on GitHub
1. Defining the Problem
  • Collections and threads
  • Use Queue with single thread
  • Use Queue with multiple threads
  • Debug the Queue multiple-thread problem
2. Deconstruct the .NET Queue Class
  • Re-implement the sample with custom class
  • Examine the ExampleQueue code
3. Using Thread-Safe Code with Standard Collections
  • Rewrite the code to support thread locks
  • Use a lock statement and mutex to make thread-safe
  • Why locking is not a good solution
  • How the concurrent collections are better
4. Overview of Thread-Safe Collections
  • Compare standard and concurrent collections
  • Categories of collections
5. Work with the ConcurrentDictionary Class
  • Create a dictionary
  • Use TryAdd to add an item
  • Use TryRemove to remove an item
  • The GetOrAdd method to get or add an item
6. Updating Data in ConcurrentDictionary
  • Review the updated example application
  • Potential problems with updating an item
  • Use TryUpdate to update dictionary value
  • Use a while loop with TryUpdate
  • Use the AddOrUpdate method
  • Why ICollection and other interfaces are not thread-safe
  • Inspect your APIs for ICollection usage
7. Work with the Producer-Consumer Collections
  • Overview of the producer-consumer collections
  • Work with ConcurrentQueue
  • Work with the ConcurrentStack
  • Work with the ConcurrentBag
8. Using the BlockingCollection
  • Understand the BlockingCollection
  • Use the BlockingCollection with ConcurrentQueue
  • Use the CompleteAdding method
  • Use other collections with BlockingCollection
  • Read items with multiple consumers
  • Create items with multiple producers
Continuing Your Journey
  • Next steps

Taught by

Walt Ritscher

Reviews

4.7 rating at LinkedIn Learning based on 101 ratings

Start your review of Advanced C#: Thread-Safe Data with Concurrent Collections

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.