I need one thread to modify Queue (both adding and removing elements) and another thread only to call Queue.Count. Would it be safe or I need to use locks or ConcurrentQueue?
I need one thread to modify Queue (both adding and removing elements) and another
Share
The Queue property is not thread-safe, as per the docs.
But it is an atomic int, the worst that could happen is that you read the wrong (outdated) value. Which may or may not be a problem.
But since you’ll have to do something to prevent your reading thread from caching the value you might as well
lock().