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.

Rewrite the code to support thread locks

Rewrite the code to support thread locks - C# Tutorial

From the course: Advanced C#: Thread-Safe Data with Concurrent Collections

Rewrite the code to support thread locks

- When you work with threads in the dot and framework it's useful to look at some of the types that are in system dot threading and see if they can be used to help you manage the state or the access to parts of your code from multiple threads. In fact, if you already are an experienced multi-threaded developer, you've probably thought as you've been watching the demos that you know there are ways to prevent my code from accessing the instance members of the queue type by multiple threads And that's what we're going to look at here is some ways we can lock sections of code. There's a lot of different locking scenarios in here depending on what kind of a scenario you'll need. For instance, there's the barrier class there is the interlock class there's one called EventWaitHandle. The ones we'll look at in this chapter I'll discuss monitor briefly and we'll look at Mutex. I modified my code somewhat. I still have the robot…

Contents