diff --git a/Pilz.Net/Api/ApiServer.cs b/Pilz.Net/Api/ApiServer.cs index 5557680..e24f0c3 100644 --- a/Pilz.Net/Api/ApiServer.cs +++ b/Pilz.Net/Api/ApiServer.cs @@ -100,13 +100,14 @@ public class ApiServer(string apiUrl) : IApiServer { if (MaxConcurentConnections == int.MaxValue) return; // Unlimited in this case - semaphore ??= new(MaxConcurentConnections); + semaphore ??= new(MaxConcurentConnections, MaxConcurentConnections); semaphore.Wait(); } protected virtual void FreeSlot() { - semaphore?.Release(); + if (semaphore != null && semaphore.CurrentCount < MaxConcurentConnections) + semaphore.Release(); } public virtual void RegisterHandler(T instance) where T : class