From 1d67f77e838df88b0223083378fb3381e691b4ae Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周四, 03 4月 2025 08:31:46 +0800 Subject: [PATCH] 优化 --- Api/Controllers/WareAuthorizeController.cs | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/Api/Controllers/WareAuthorizeController.cs b/Api/Controllers/WareAuthorizeController.cs index 747d139..9d480af 100644 --- a/Api/Controllers/WareAuthorizeController.cs +++ b/Api/Controllers/WareAuthorizeController.cs @@ -7,6 +7,10 @@ [Route("[controller]")] public class WareAuthorizeController : ControllerBase { + + private static bool isRuning_Fun_MianAgvFun = false; + private static readonly SemaphoreSlim semaphore_MianAgvFun = new SemaphoreSlim(1, 1); + private readonly ILogger<WareAuthorizeController> _logger; public WareAuthorizeController(ILogger<WareAuthorizeController> logger) @@ -20,10 +24,18 @@ /// <param name="input"></param> /// <returns></returns> [HttpGet(Name = "ValidateLicense")] - public AuthorizeFunRetEntity ValidateLicense([FromQuery] ValidateLicenseInput input) + public async Task<AuthorizeFunRetEntity> ValidateLicense([FromQuery] ValidateLicenseInput input) { + if (isRuning_Fun_MianAgvFun) + { + //认为是验证成功,不要并发导致读取授权文件失败 + return AuthorizeFunRetEntity.Success("成功", null); + } try { + await semaphore_MianAgvFun.WaitAsync(); + isRuning_Fun_MianAgvFun = true; + //if (input == null) //{ // return AuthorizeFunRetEntity.Fail("参数不能为空"); @@ -39,6 +51,11 @@ { return AuthorizeFunRetEntity.Fail("异常:" + ex.Message); } + finally + { + semaphore_MianAgvFun.Release(); + isRuning_Fun_MianAgvFun = false; + } } } } \ No newline at end of file -- Gitblit v1.9.3