I'm trying to find solution for more threads writing to a queue and a single thred is reading from it.
I found ConcurrentQueue
it has TryDequeue(T)
that is thread safe but I'm not sure if Enqueue(T)
is thread safe too when writing to the queue from more threads.
Any idea?
Yes, the whole point of the concurrent collections is that they're thread-safe. It's fine to write to ConcurrentQueue<T>
from multiple threads.
From the documentation:
All public and protected members of
ConcurrentQueue<T>
are thread-safe and may be used concurrently from multiple threads.
See more on this question at Stackoverflow