A .NET Standard 2.0 library that provides a class that uses SemaphoreSlim but allows a negative initialCount
. This could be used, for example, when starting to throttle requests but initially already have more concurrent requests than the maximum you want to start allowing.
Supports .NET Framework 4.6.1 or later, .NET Core 2.0 or later, and .NET 5.0 or later.
The recommended means is to use NuGet, but you could also download the source code from here.
// there are 11 concurrent requests, and we want to start limiting to 10.
// SemaphoreSlim does not allow negative initialCount.
var mySemaphore = new SemaphoreSlimThrottle(-1, 10);
For more information, read the documentation for SemaphoreSlim.