> I'd suggest doing the same for instance locks as well. That way you
know nothing else is going to be locking on the same reference, as
nothing *has* the same reference. It also means you can use finer-
As a note, if you will be supplying a "SyncRoot" property (e.g using
ICollection, IList, etc.) for your object, then it probably does not matter
if you use "this" or another internal object as any class that can gain
access to your object ref could also get access to SyncRoot and lock either
or both. So the net effect would be the same if using one lock. You will
notice most (if not all) of the Framework classes that derive from
ICollection and return a SyncRoot (i.e. Array, Queue, Stack, ArrayList,
HashTable, etc.) just return "this" as the sync object probably for this
reason. If you don't need or want to expose a sync object, then I agree a
private object is probably better.
--
William Stacey, MVP