初步完成TimedTask,等待测试

This commit is contained in:
Falcon 2025-02-19 16:45:17 +08:00
parent 4bb1064352
commit 4c362574e6
2 changed files with 7 additions and 3 deletions

View File

@ -8,7 +8,7 @@
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile> <DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.13.0</Version> <Version>2.14.0</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -9,7 +9,7 @@ namespace Falcon.SugarApi.TimedBackgroundTask
/// <summary> /// <summary>
/// 由定时器驱动的后台任务 /// 由定时器驱动的后台任务
/// </summary> /// </summary>
public class TimedTask:BackgroundService, IDisposable public abstract class TimedTask:BackgroundService, IDisposable
{ {
/// <summary> /// <summary>
/// 日志记录器 /// 日志记录器
@ -25,7 +25,7 @@ namespace Falcon.SugarApi.TimedBackgroundTask
/// </summary> /// </summary>
/// <param name="cancellationToken">退出信号</param> /// <param name="cancellationToken">退出信号</param>
/// <returns>如果继续执行返回True否则False</returns> /// <returns>如果继续执行返回True否则False</returns>
public virtual async Task<bool> Run(CancellationToken cancellationToken) => await Task.FromResult(true); public abstract Task<bool> Run(CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Timer心跳 /// Timer心跳
@ -127,8 +127,12 @@ namespace Falcon.SugarApi.TimedBackgroundTask
this.NextTickTime = s.GetNextOccurrence(DateTime.Now); this.NextTickTime = s.GetNextOccurrence(DateTime.Now);
} }
/// <summary>
/// 释放对象
/// </summary>
public override void Dispose() { public override void Dispose() {
this._timer?.Dispose(); this._timer?.Dispose();
GC.SuppressFinalize(this);
base.Dispose(); base.Dispose();
} }
} }