后台长时任务重写在释放时候停止任务

This commit is contained in:
falcon 2022-04-02 09:13:44 +08:00
parent 4077501379
commit 5fa1a78ddf

View File

@ -8,7 +8,7 @@ namespace Falcon.SugarApi.BackTask
/// <summary>
/// 长时间执行的后台任务
/// </summary>
public abstract class BackgroundLongTask : BackgroundService
public abstract class BackgroundLongTask : BackgroundService, IDisposable
{
/// <summary>
/// 要执行的任务
@ -70,5 +70,13 @@ namespace Falcon.SugarApi.BackTask
this.TokenSource.Cancel();
return base.StopAsync(cancellationToken);
}
/// <summary>
/// 释放空间,结束任务
/// </summary>
public override void Dispose() {
this.TokenSource.Cancel();
base.Dispose();
}
}
}