Using ConcurrentQueue
In this section, we will create a sample project that is a simplified version of a realistic scenario. We are going to create an order queuing system using ConcurrentQueue<T>
. This application will be a console application that enqueues orders for two customers in parallel. We will create five orders for each customer, and to mix up the order of the queue, each customer queuing process will use a different Task.Delay
between calls to Enqueue
. The final output should show a mix of orders dequeued for the first customer and the second customer. Remember that ConcurrentQueue<T>
employs first in, first out (FIFO) logic:
- Let’s start by opening Visual Studio and creating a .NET console application named
ConcurrentOrderQueue
. - Add a new class to the project named
Order
:public class Order { public int Id { get; set; } public string? ItemName { get; set; } public int ItemQty...