I have a Queue object that I need to ensure is thread-safe. Would it be better to use a lock object like this:
lock(myLockObject) { //do stuff with the queue
This way we don't need to lock the queue just to find out it was empty.
object item; if (queue.Count > 0) { lock (queue) { if (queue.Count > 0) { item = queue.Dequeue(); } } }