A
AMercer
The documentation has many examples that use "SyncLock Me". But the
documentation of the SyncLock Statement under "Programming Practices" says
you should not do this (see the snip below), and I think the cited reason is
pretty weak. What do you think?
SyncLock statement snip:
"The lockobject expression should always evaluate to an object that belongs
exclusively to your class. You should declare a Private object variable to
protect data belonging to the current instance, or a Private Shared object
variable to protect data common to all instances.
You should not use the Me keyword to provide a lock object for instance
data. If code external to your class has a reference to an instance of your
class, it could use that reference as a lock object for a SyncLock block
completely different from yours, protecting different data. In this way, your
class and the other class could block each other from executing their
unrelated SyncLock blocks. Similarly locking on a string can be problematic
since any other code in the process using the same string will share the same
lock."
documentation of the SyncLock Statement under "Programming Practices" says
you should not do this (see the snip below), and I think the cited reason is
pretty weak. What do you think?
SyncLock statement snip:
"The lockobject expression should always evaluate to an object that belongs
exclusively to your class. You should declare a Private object variable to
protect data belonging to the current instance, or a Private Shared object
variable to protect data common to all instances.
You should not use the Me keyword to provide a lock object for instance
data. If code external to your class has a reference to an instance of your
class, it could use that reference as a lock object for a SyncLock block
completely different from yours, protecting different data. In this way, your
class and the other class could block each other from executing their
unrelated SyncLock blocks. Similarly locking on a string can be problematic
since any other code in the process using the same string will share the same
lock."