diff --git a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs index 99126f7d..faa40f75 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs @@ -173,7 +173,8 @@ namespace Tnb.WarehouseMgr public override Task StopAsync(CancellationToken cancellationToken) { IsStarted = false; - return base.StopAsync(cancellationToken); + return Task.FromResult(IsStarted); + //return base.StopAsync(cancellationToken); } private Task TaskDelay(TimeSpanUnit timeType, int interval) diff --git a/system/Tnb.OAuth/OAuthService.cs b/system/Tnb.OAuth/OAuthService.cs index a1d76f02..d9e0a43e 100644 --- a/system/Tnb.OAuth/OAuthService.cs +++ b/system/Tnb.OAuth/OAuthService.cs @@ -144,8 +144,7 @@ public class OAuthService : IDynamicApiController, ITransient private readonly IMHandler _imHandler; private readonly BackgroundService _backgroundService; //added by ly on 20230916 - private static Dictionary _hostSvcRun = new(); - + private static CancellationTokenSource stopTimedTaskSvcCTS = new(); /// @@ -295,17 +294,11 @@ public class OAuthService : IDynamicApiController, ITransient //modify by ly on 20230918 登录成功后启动定时服务 if (!userId.IsNullOrWhiteSpace()) { - if (!_hostSvcRun.TryGetValue("IsStarted", out bool isStarted)) + var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted"); + if (isStartedProperty?.GetValue(_backgroundService) is bool isStarted && !isStarted) { - var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted"); - isStarted = Convert.ToBoolean(isStartedProperty?.GetValue(_backgroundService)); - _hostSvcRun["IsStarted"] = isStarted; + await _backgroundService.StartAsync(stopTimedTaskSvcCTS.Token); } - if (!isStarted) - { - await _backgroundService.StartAsync(CancellationToken.None); - } - } @@ -409,9 +402,9 @@ public class OAuthService : IDynamicApiController, ITransient [HttpGet("Logout")] public async Task Logout([FromQuery] string ticket) { - - await _backgroundService.StopAsync(CancellationToken.None); - + //modify by ly on 20230918 + await _backgroundService.StopAsync(stopTimedTaskSvcCTS.Token); + stopTimedTaskSvcCTS.Cancel(); UserManager.AsscessToken = string.Empty; var tenantId = _userManager.TenantId ?? "default";