From f05ece37e5d23269b59cc56c88d57f1d9e008554 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 19 Sep 2023 15:57:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E5=90=AF=E5=8A=A8=EF=BC=8C?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E5=8F=8D=E5=B0=84=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=94=BE=E5=88=B0=E6=9C=AC=E5=9C=B0=E7=BC=93=E5=AD=98?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TimedTaskBackgroundService.cs | 2 +- system/Tnb.OAuth/OAuthService.cs | 27 ++++++++----------- 2 files changed, 12 insertions(+), 17 deletions(-) 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); }