From the course: Advanced C#: Thread-Safe Data with Concurrent Collections
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Use Queue with single thread - C# Tutorial
From the course: Advanced C#: Thread-Safe Data with Concurrent Collections
Use Queue with single thread
- [Narrator] The Microsoft documentation tells us that we're not supposed to use any of the standard collections in a multi threaded scenario without taking care of the right specific thread safe code. Well, we'll look at in this chapter as an example of working with the queue class and adding items to the queue and removing items from the queue. So we should start by looking at the sample code. What I'm doing here in line eight is creating a class level variable of type queue. So I'm, will instantiate a queue. And the data that goes inside the queue is instances of this robot type. And that's a class that I wrote, we're simulating a simple game application that has robots compete on teams. So you see that I have a struct here. It's got an ID, the name of the robot, the team name, and a team color. I primarily use the team color when I'm outputting the information to the console so it's easier to differentiate which…