From c02763ae9ab1c8fd8fe5c03fad1fb24982c88200 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Tue, 28 Jan 2025 07:37:43 +0100 Subject: [PATCH] release semaphore only if requied --- Pilz.Net/Api/ApiServer.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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