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.

Use Queue with multiple threads

Use Queue with multiple threads

- [Instructor] We are done using the code in Demo1, so I've commented out that method call and I've un-commented Demo2. Here in Demo1, let's refresh our memories of what happened in here. We had a single thread, or the main application thread, enter Demo1, and it's calling all of the code in Demo1, so it's the thread that's calling Setup Team1 and Setup Team2, and processing the rest of this method call. That's not the case here in Demo2. So, what I'm doing here is the main thread enters Demo2, and when we get to line 43, I'm asking the .net framework to spin up a worker thread and have it process the instructions that are inside Setup Team1. And then, on the next line, I ask for another worker thread to process the instructions that are in Setup Team2. The main thread enters here and runs this line of code, then the worker thread runs the code inside of Setup Team1, another worker thread runs the code in Setup Team2, and…

Contents