LockRecursionPolicy Enum

System.Threading

Specifies whether to allow re-entrant locking. This enumeration is used by the LockSynchronization class.

Members

NoRecursion
(0)
Reentrant locking is not allowed. If a thread attempts to acquire a lock that it already owns, a LockSynchronizationException is thrown.
RecursionAllowed
(1)
Reentrant locking is allowed. If a thread attempts to acquire a lock that it already owns, the lock is acquired again.

Remarks

The LockRecursionPolicy enumeration is used to configure the behavior of re-entrant locking in the LockSynchronization class. This policy determines how the system handles situations where a thread tries to acquire a lock that it already holds.

When LockRecursionPolicy.NoRecursion is specified, attempting to re-acquire a held lock will result in a LockSynchronizationException. This is the default behavior and helps prevent potential deadlocks in scenarios where re-entrant locking is not intended.

Conversely, when LockRecursionPolicy.RecursionAllowed is set, a thread can acquire the same lock multiple times. This can be useful in complex hierarchical locking scenarios, but it requires careful management to avoid infinite recursion or other concurrency issues.

Syntax

                    public enum LockRecursionPolicy
                

See Also