You can - but I didn't do it at all. Personally, I usually try to block regular instances of System.Object that are not used for anything else, and ideally are not even exposed to any code other than locking classes on them. Thus, you can be absolutely sure that nothing else will be blocked.
In this case, it looks like you have control over the queues, so you know that they will not be used by other code, but it is possible that the code inside Queue<T> will be blocked on this . This is probably not the case, but this is what I would worry about.
Basically, I'm sorry that .NET did not use the Java approach for a “monitor for every object” —I would like Monitor be an instance of the class.
(I assume that you are only actually reading a dictionary from multiple threads? It is unsafe to use dictionaries for multithreaded read / write.)
source share