C#

C#

Made by DeepSource

Acquiring lock on local variables is error-prone CS-W1094

Bug risk
Critical

Trying to acquire a lock on a local variable is error-prone as different threads may end up locking on different instances of the same variable. Instead, you should be locking on a class field that is preferably designated as private and readonly, i.e. a dedicated object. Microsoft guidelines explicitly state that you should avoid locking on: 1. this,

  1. System.Type instances, and,

  2. string-s and literals.

It is recommended that you fix this issue as soon as possible to avoid race conditions that undermine the synchronicity of your application.

References