继续调整,原逻辑有问题

This commit is contained in:
alex
2023-09-18 15:48:02 +08:00
parent 6cc0529d60
commit 18b72a8bad
2 changed files with 9 additions and 15 deletions

View File

@@ -173,7 +173,8 @@ namespace Tnb.WarehouseMgr
public override Task StopAsync(CancellationToken cancellationToken) public override Task StopAsync(CancellationToken cancellationToken)
{ {
IsStarted = false; IsStarted = false;
return base.StopAsync(cancellationToken); return Task.FromResult(IsStarted);
//return base.StopAsync(cancellationToken);
} }
private Task TaskDelay(TimeSpanUnit timeType, int interval) private Task TaskDelay(TimeSpanUnit timeType, int interval)

View File

@@ -144,8 +144,7 @@ public class OAuthService : IDynamicApiController, ITransient
private readonly IMHandler _imHandler; private readonly IMHandler _imHandler;
private readonly BackgroundService _backgroundService; //added by ly on 20230916 private readonly BackgroundService _backgroundService; //added by ly on 20230916
private static Dictionary<string, bool> _hostSvcRun = new(); private static CancellationTokenSource stopTimedTaskSvcCTS = new();
/// <summary> /// <summary>
@@ -294,18 +293,12 @@ public class OAuthService : IDynamicApiController, ITransient
//modify by ly on 20230918 登录成功后启动定时服务 //modify by ly on 20230918 登录成功后启动定时服务
if (!userId.IsNullOrWhiteSpace()) if (!userId.IsNullOrWhiteSpace())
{
if (!_hostSvcRun.TryGetValue("IsStarted", out bool isStarted))
{ {
var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted"); var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted");
isStarted = Convert.ToBoolean(isStartedProperty?.GetValue(_backgroundService)); if (isStartedProperty?.GetValue(_backgroundService) is bool isStarted && !isStarted)
_hostSvcRun["IsStarted"] = isStarted;
}
if (!isStarted)
{ {
await _backgroundService.StartAsync(CancellationToken.None); await _backgroundService.StartAsync(stopTimedTaskSvcCTS.Token);
} }
} }
@@ -409,9 +402,9 @@ public class OAuthService : IDynamicApiController, ITransient
[HttpGet("Logout")] [HttpGet("Logout")]
public async Task Logout([FromQuery] string ticket) public async Task Logout([FromQuery] string ticket)
{ {
//modify by ly on 20230918
await _backgroundService.StopAsync(CancellationToken.None); await _backgroundService.StopAsync(stopTimedTaskSvcCTS.Token);
stopTimedTaskSvcCTS.Cancel();
UserManager.AsscessToken = string.Empty; UserManager.AsscessToken = string.Empty;
var tenantId = _userManager.TenantId ?? "default"; var tenantId = _userManager.TenantId ?? "default";