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.
Potential problems with updating an item - C# Tutorial
From the course: Advanced C#: Thread-Safe Data with Concurrent Collections
Potential problems with updating an item
- [Instructor] We'll start out by looking at the classic way that you modify the contents of a dictionary, by using the keyed index into the dictionary, retrieve the current value, make some changes to it, and then reinsert it back into the dictionary. At this point on line 61 I have four robots in the concurrent dictionary and I'm going to send one of those robots out to look for some Gems and then I'm going to update its Count. So I start here on line 61 by calling a method that'll search for Gems, which is here on line 93. And as you can see, it's just a simple random number generator. So the robot will get a new set of Gems from one to five. That's what I'm doing here on line 61, I search for the Gems, and I find them and put it in this variable. Next I output the information to the console. Here on line 64 I look for the key robot three and I retrieve the current GemCount that's there. Then on line 68 I add the two…
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)
-
-
-