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;