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++;
}
C# 14 · Async, errors and resources
Use a lock to let only one thread run a block at a time.
private readonly Lock _gate = new();
lock (_gate)
{
counter++;
}
Was this page helpful?