From 4c362574e6e51142e7566b227c1b960ca5f51a99 Mon Sep 17 00:00:00 2001 From: Falcon <12919280+falconfly@user.noreply.gitee.com> Date: Wed, 19 Feb 2025 16:45:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90TimedTask?= =?UTF-8?q?=EF=BC=8C=E7=AD=89=E5=BE=85=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Falcon.SugarApi/Falcon.SugarApi.csproj | 2 +- Falcon.SugarApi/TimedBackgroundTask/TimedTask.cs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Falcon.SugarApi/Falcon.SugarApi.csproj b/Falcon.SugarApi/Falcon.SugarApi.csproj index 199e672..202a601 100644 --- a/Falcon.SugarApi/Falcon.SugarApi.csproj +++ b/Falcon.SugarApi/Falcon.SugarApi.csproj @@ -8,7 +8,7 @@ bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml true true - 2.13.0 + 2.14.0 diff --git a/Falcon.SugarApi/TimedBackgroundTask/TimedTask.cs b/Falcon.SugarApi/TimedBackgroundTask/TimedTask.cs index fadd64b..38708bb 100644 --- a/Falcon.SugarApi/TimedBackgroundTask/TimedTask.cs +++ b/Falcon.SugarApi/TimedBackgroundTask/TimedTask.cs @@ -9,7 +9,7 @@ namespace Falcon.SugarApi.TimedBackgroundTask /// /// 由定时器驱动的后台任务 /// - public class TimedTask:BackgroundService, IDisposable + public abstract class TimedTask:BackgroundService, IDisposable { /// /// 日志记录器 @@ -25,7 +25,7 @@ namespace Falcon.SugarApi.TimedBackgroundTask /// /// 退出信号 /// 如果继续执行返回True,否则False - public virtual async Task Run(CancellationToken cancellationToken) => await Task.FromResult(true); + public abstract Task Run(CancellationToken cancellationToken); /// /// Timer心跳 @@ -127,8 +127,12 @@ namespace Falcon.SugarApi.TimedBackgroundTask this.NextTickTime = s.GetNextOccurrence(DateTime.Now); } + /// + /// 释放对象 + /// public override void Dispose() { this._timer?.Dispose(); + GC.SuppressFinalize(this); base.Dispose(); } }