There is a ConcurrentQueue instance and two threads that access it concurrently. One thread enqueues items continuesly (may be enqueue few items in 100 micro seconds) and other thread TryDequeue item by item and do some processing. There is a ManualResetEvent to signal the processing thread after any item enqueue (this is not quite related to this question)
In this case, is there any possibility of adding items in wrong order to the ConcurrentQueue. I know it’s thread safe but just want to make sure whether it does not mess with the order of items when enqueue and dequeue quite faster.
There is absolutely no way that the items can be out of order.
First of all, a queue by definition enforces a FIFO order: you put elements at one end and take them out at the other end. And since this is done by a single-producer-single-consumer model, it’s absolutely safe.