All rules
IDE0330Language rules (code-block preferences)

Prefer 'System.Threading.Lock'

Prefer 'System.Threading.Lock'

Microsoft docs

Description

This rule flags places where you can use the .NET 9+ type System.Threading.Lock instead of an object lock.

Example

// Code with violations.
private object _gate = new object();

void M()
{
    lock (_gate) { }
}

// Fixed code.
private Lock _gate = new Lock();

void M()
{
    lock (_gate) { }
}

Configurable options

Vote for the value each option should take in the generated .editorconfig.

csharp_prefer_system_threading_lock
default: true
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0