继续调整,原逻辑有问题

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)
{
IsStarted = false;
return base.StopAsync(cancellationToken);
return Task.FromResult(IsStarted);
//return base.StopAsync(cancellationToken);
}
private Task TaskDelay(TimeSpanUnit timeType, int interval)

View File

@@ -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<string, bool> _hostSvcRun = new();
private static CancellationTokenSource stopTimedTaskSvcCTS = new();
/// <summary>
@@ -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";