Microsoft guidelines specifically state that lock
s should not be obtained on this
, System.Type
s, and string
instances. Doing so may cause deadlock or lock contention, thereby affecting your application's execution and reliability. It is generally recommended that you dedicate a private
readonly
object
solely for locking.
lock(this)
{
// ...
}
// _lockObj is an `object` that is class' private readonly member.
lock(_lockObj)
{
// ...
}