An asynchronous .NET library that allows you to lock based on a key (keyed semaphores), limiting concurrent threads sharing the same key to a specified number, with optional pooling for reducing memory allocations.
$ dotnet add package AsyncKeyedLockAn asynchronous .NET Standard 2.0 library that allows you to lock based on a key.
The recommended means is to use NuGet, but you could also download the source code from here.
using (var lockObj = await AsyncDuplicateLock.LockAsync(myObject))
{
...
}
This library is based on Stephen Cleary's solution.