From the course: Advanced C#: Thread-Safe Data with Concurrent Collections
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Inspect your APIs for ICollection usage - C# Tutorial
From the course: Advanced C#: Thread-Safe Data with Concurrent Collections
Inspect your APIs for ICollection usage
- [Instructor] Now we know that ConcurrentDictionary implements ICollection and that we're not supposed to work with the add method or remove method because they're not thread safe. Well, the only way to see those methods is if we explicitly cast. So I would have to write code like this. Now I've got this variable called collection, I take my instance of ConcurrentDictionary, which is called robotGems, and I cast it to ICollection of KeyValuePair, of string int. And now that I've done that, I can go to collection dot and I have the add method and the remove method. So we don't want to do that so I will comment out this line of code so we don't make that mistake and we're done, right? Not really. Think about all of the applications you've worked with. You've got libraries that have helper methods and there's APIs out there that have lots of methods that you use in your applications and a lot of times, those methods take…
Contents
-
-
-
-
-
-
-
-
(Locked)
Review the updated example application1m 34s
-
(Locked)
Potential problems with updating an item3m
-
(Locked)
Use TryUpdate to update dictionary value2m 4s
-
(Locked)
Use a while loop with TryUpdate2m 5s
-
(Locked)
Use the AddOrUpdate method4m 16s
-
(Locked)
Why ICollection and other interfaces are not thread-safe2m 32s
-
(Locked)
Inspect your APIs for ICollection usage2m 40s
-
(Locked)
-
-
-