C# 14 · Async, errors and resources

Protect shared state

Use a lock to let only one thread run a block at a time.

private readonly Lock _gate = new();

lock (_gate)
{
    counter++;
}

Official C# 14 documentation

More async, errors and resources commands

All async, errors and resources commands · C# 14 cheatsheet

Was this page helpful?