From 7aaaacb309feef129a5e33d206e0f5aa2fd2eebd Mon Sep 17 00:00:00 2001 From: Falcon <12919280+falconfly@user.noreply.gitee.com> Date: Wed, 5 Mar 2025 11:24:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Falcon.SugarApi/TimedTask/TimedTask.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Falcon.SugarApi/TimedTask/TimedTask.cs b/Falcon.SugarApi/TimedTask/TimedTask.cs index f4109f7..f29b858 100644 --- a/Falcon.SugarApi/TimedTask/TimedTask.cs +++ b/Falcon.SugarApi/TimedTask/TimedTask.cs @@ -32,17 +32,17 @@ namespace Falcon.SugarApi.TimedTask /// /// 执行计划的Cron串 /// - public abstract string CronSchedule { get; } + protected abstract string CronSchedule { get; } /// - /// Timer心跳 + /// Timer心跳 毫秒 /// - public virtual int Heartbeat { get; protected set; } = 1; + public virtual int Heartbeat { get; protected set; } = 1000; /// /// 获取下次执行任务的计划 /// - public CronExpression Schedule { get; private set; } + protected CronExpression Schedule { get; private set; } /// /// 任务正在运行 @@ -95,7 +95,7 @@ namespace Falcon.SugarApi.TimedTask public TimedTask(IServiceProvider service) { this.Service = service; this.Logger = service.GetService(typeof(ILogger<>).MakeGenericType(GetType())) as ILogger; - _timer = new PeriodicTimer(TimeSpan.FromSeconds(this.Heartbeat)); + _timer = new PeriodicTimer(TimeSpan.FromMilliseconds(this.Heartbeat)); this.Schedule = new CronExpression(this.CronSchedule); } @@ -113,7 +113,10 @@ namespace Falcon.SugarApi.TimedTask if(stoppingToken.IsCancellationRequested) { break; } - if(this._isRunning || DateTime.Now < this.NextTickTime) { + if(this._isRunning) { + continue; + } + if(DateTime.Now < this.NextTickTime) { continue; } this._isRunning = true;