LockRecursionPolicy Enumeration

public enum LockRecursionPolicy

Specifies how to handle reentrant lock acquisitions by the same thread.

Namespace

System.Threading

Assembly

System.Runtime.dll

Members

Remarks

The LockRecursionPolicy enumeration is used by the ReaderWriterLockSlim class to determine how to treat recursive lock acquisitions. When a thread attempts to acquire a lock that it already holds, the behavior is determined by the LockRecursionPolicy specified for the ReaderWriterLockSlim instance.

Setting the policy to NoRecursion can help prevent deadlocks caused by unintended recursive lock acquisitions. However, if your application logic genuinely requires recursive lock acquisitions, you should use the Recursion policy.

Important: If you set the LockRecursionPolicy to NoRecursion and a thread attempts to acquire a lock it already holds, an InvalidOperationException will be thrown. This is a safeguard against potential deadlocks.

See Also