C#

C#

Made by DeepSource

Lock is obtained on an entity that does not guarantee reliable mutual exclusion CS-W1044

Bug risk
Major

Microsoft guidelines specifically state that locks should not be obtained on this, System.Types, 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.

Bad Practice

lock(this)
{
    // ...
}

Recommended

// _lockObj is an `object` that is class' private readonly member.
lock(_lockObj)
{
    // ...
}

Reference