๐ .NET Nuget for a basic asynchronous locking recipe
Find it on nuget!
PM> Install-Package AsyncLock.NET -Version 6.0.1
// example of an asynchronous operation setting a SignalR connection
HubConnection connection;
await AsyncLock.ExecuteWithLock(async () =>
{
connection = await GetConnection("https://that.place.on.the.internet/hub");
});
await connection.StartAsync();
// example of setting the maximum number of requests for the semaphore
// that can be granted concurrently which defaults to one
AsyncLock.MaxCount = 5;
// act
await AsyncLock.ExecuteWithLock(async () =>
{
await Task.Delay(1000);
return "Test";
});