Skip to main content
Source: AL0011LockKeywordAnalyzer.cs

Description

The lock keyword on object/non-Lock types should be replaced with the Lock class from System.Threading.

Bad Code

private object _syncRoot = new();
lock (_syncRoot) { }

Good Code

private Lock _syncRoot = new();
lock (_syncRoot) { }

Properties

  • Category: Threading
  • Severity: Warning
  • Enabled by default: True
  • Code fix available: False

Configuration

dotnet_diagnostic.AL0011.severity = warning