AsyncKeyedLock 2.0.1

AsyncKeyedLock AsyncKeyedLock

GitHub branch checks state Nuget Nuget

An asynchronous .NET Standard 2.0 library that allows you to lock based on a key (keyed semaphores), only allowing a defined number of concurrent threads that share the same key.

For example, if you're processing transactions, you may want to limit to only one transaction per user so that the order is maintained, but meanwhile allowing parallel processing of multiple users.

Installation

The recommended means is to use NuGet, but you could also download the source code from here.

Usage

var asyncKeyedLocker = new AsyncKeyedLocker();
using (var lockObj = await asyncKeyedLocker.LockAsync(myObject))
{
	...
}

You can also set the maximum number of requests for the semaphore that can be granted concurrently (set to 1 by default):

var asyncKeyedLocker = new AsyncKeyedLocker(2);

If you would like to see how many concurrent requests there are for a semaphore for a given key:

int myCount = asyncKeyedLocker.GetCount(myObject);

And if for some reason you need to force release the requests in the semaphore for a key:

asyncKeyedLocker.ForceRelease(myObject);

You may also use Dependency Injection to inject an instance of AsyncKeyedLock.

Credits

This library is based on Stephen Cleary's solution.

Showing the top 20 packages that depend on AsyncKeyedLock.

Updated documentation.

.NET Standard 2.0

  • No dependencies.

Version Downloads Last updated
7.1.8 4 12/08/2025
7.1.8-beta5 3 12/08/2025
7.1.8-beta4 3 12/08/2025
7.1.8-beta3 4 12/08/2025
7.1.8-beta2 3 12/08/2025
7.1.8-beta 3 12/08/2025
7.1.7 8 10/07/2025
7.1.6 22 05/09/2025
7.1.5-alpha 15 05/09/2025
7.1.4 18 03/03/2025
7.1.4-preview 18 03/03/2025
7.1.3 21 03/03/2025
7.0.2 18 03/03/2025
7.0.1 18 03/03/2025
7.0.0 18 03/03/2025
7.0.0-rc3 17 03/03/2025
7.0.0-rc2 17 03/03/2025
7.0.0-rc1 17 03/03/2025
7.0.0-beta 19 03/03/2025
7.0.0-alpha 18 03/03/2025
6.4.2 23 04/30/2024
6.4.1 19 04/30/2024
6.4.0 18 04/30/2024
6.3.4 48 02/21/2024
6.3.4-rc 21 02/21/2024
6.3.4-beta 23 02/21/2024
6.3.3 23 02/21/2024
6.3.2 21 02/21/2024
6.3.0 20 02/21/2024
6.2.6 20 02/21/2024
6.2.5 20 02/21/2024
6.2.4 23 02/21/2024
6.2.3 22 02/21/2024
6.2.3-beta 22 02/21/2024
6.2.2 20 02/21/2024
6.2.1 158 01/21/2024
6.2.0 23 02/21/2024
6.1.1 22 02/21/2024
6.1.1-rc 21 02/21/2024
6.1.1-beta 21 02/21/2024
6.1.0 21 02/21/2024
6.0.5 20 02/21/2024
6.0.5-alpha 21 02/20/2024
6.0.4 20 02/21/2024
6.0.4-rc6 20 02/21/2024
6.0.4-rc5 20 02/21/2024
6.0.4-rc3 21 02/21/2024
6.0.4-rc 22 02/21/2024
6.0.4-beta 22 02/21/2024
6.0.4-alpha 23 02/20/2024
6.0.3 20 02/21/2024
6.0.2 21 02/21/2024
6.0.1 22 02/21/2024
5.1.2 22 02/21/2024
5.1.1 22 02/21/2024
5.1.0 21 02/21/2024
5.0.4 19 02/21/2024
5.0.3 20 02/21/2024
5.0.3-rc 20 02/21/2024
5.0.2-rc 20 02/21/2024
5.0.1 22 02/21/2024
4.0.2 20 02/21/2024
3.2.3 21 02/21/2024
3.2.1 22 02/21/2024
3.2.0 19 02/21/2024
3.0.1 22 02/21/2024
3.0.0 21 02/21/2024
2.0.3 21 02/21/2024
2.0.2 21 02/21/2024
2.0.1 21 02/21/2024
2.0.0 20 02/21/2024
1.1.0 21 02/21/2024
1.0.1 20 02/21/2024
1.0.0 22 02/21/2024