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

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