diff --git a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs index faa40f75..8523ef03 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs @@ -173,7 +173,7 @@ namespace Tnb.WarehouseMgr public override Task StopAsync(CancellationToken cancellationToken) { IsStarted = false; - return Task.FromResult(IsStarted); + return Task.CompletedTask; //return base.StopAsync(cancellationToken); } diff --git a/system/Tnb.OAuth/OAuthService.cs b/system/Tnb.OAuth/OAuthService.cs index ed3bb917..1ffc3e16 100644 --- a/system/Tnb.OAuth/OAuthService.cs +++ b/system/Tnb.OAuth/OAuthService.cs @@ -146,7 +146,7 @@ public class OAuthService : IDynamicApiController, ITransient private readonly BackgroundService _backgroundService; //added by ly on 20230916 private static CancellationTokenSource stopTimedTaskSvcCTS = new(); - private static Dictionary> _fetchPropValue = new(); + private static Dictionary> _fetchPropValue = new(); /// @@ -296,21 +296,16 @@ public class OAuthService : IDynamicApiController, ITransient //modify by ly on 20230918 登录成功后启动定时服务 if (!userId.IsNullOrWhiteSpace()) { - var isStartedProperty = _backgroundService.GetType().GetProperty("IsStarted"); - //if (!_fetchPropValue.TryGetValue("IsStarted", out var action)) - //{ - // var isStartedProp = _backgroundService.GetType().GetProperty("IsStarted"); - // var paramExp = Expression.Parameter(typeof(BackgroundService), "_backgroundSvc"); - // var propExp = Expression.Property(paramExp, isStartedProp); - // var body = Expression.Lambda>(propExp, paramExp); - // action = body.Compile(); - // _fetchPropValue["IsStarted"] = action; - //} - //if(!action?.Invoke(_backgroundService)?.ParseToBool() ?? false) - //{ - // await _backgroundService.StartAsync(stopTimedTaskSvcCTS.Token); - //} - if (isStartedProperty?.GetValue(_backgroundService) is bool isStarted && !isStarted) + if (!_fetchPropValue.TryGetValue("IsStarted", out var action)) + { + var isStartedProp = _backgroundService.GetType().GetProperty("IsStarted"); + var paramExp = Expression.Parameter(typeof(BackgroundService), "_backgroundSvc"); + var propExp = Expression.Property(Expression.ConvertChecked(paramExp, isStartedProp.DeclaringType), isStartedProp.GetGetMethod()); + var body = Expression.Lambda>(propExp, paramExp); + action = body.Compile(); + _fetchPropValue["IsStarted"] = action; + } + if (!action?.Invoke(_backgroundService) ?? false) { await _backgroundService.StartAsync(stopTimedTaskSvcCTS.Token); }