From the course: Advanced C#: Thread-Safe Data with Concurrent Collections
Unlock this course with a free trial
Join today to access over 22,500 courses taught by industry experts.
Use the BlockingCollection with ConcurrentQueue - C# Tutorial
From the course: Advanced C#: Thread-Safe Data with Concurrent Collections
Use the BlockingCollection with ConcurrentQueue
- [Instructor] Here I'm creating a variable of type, blocking collection, and I'm storing values of integer in the blocking collection. Then in the main method, I instantiate this, if I don't tell the blocking collection, which concurrent collection to use, it will default to concurrent queue. So that's what's happening here. Now I'm going to have multiple threads running in the application, I'll have the main thread that's running demo, and I'll have two worker threads that I've launched here With these tasks, one task is going to be the producer, which will work with the blocking collection, and the other task will be the consumer. Later in this chapter, I'll look into how to work with multiple consumers and multiple producers, but there's nothing wrong with having a single producer thread and a single consumer thread working in the background. So that's what we'll look at here. The code itself and the…
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
Understand the BlockingCollection5m 42s
-
(Locked)
Use the BlockingCollection with ConcurrentQueue3m 2s
-
(Locked)
Use the CompleteAdding method3m 28s
-
(Locked)
Use other collections with BlockingCollection2m 4s
-
(Locked)
Read items with multiple consumers1m 31s
-
(Locked)
Create items with multiple producers2m 48s
-
(Locked)
-