48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using JNPF;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Logging;
|
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
|
using Tnb.WarehouseMgr.Interfaces;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
/// <summary>
|
|
/// 定时任务
|
|
/// added by ly on 20230802
|
|
/// </summary>
|
|
public class TimedTaskBackgroundService : BackgroundService
|
|
{
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
{
|
|
|
|
await Task.Run(() =>
|
|
{
|
|
CancellationTokenSource tokenSource = new();
|
|
CancellationToken token = tokenSource.Token;
|
|
var wareHouseService = App.GetRequiredService<IWareHouseService>();
|
|
TimedTask(withOutParamAction: (cts) => Task.Run(async () =>
|
|
{
|
|
while (!token.IsCancellationRequested)
|
|
{
|
|
await wareHouseService.GenTaskExecute(tokenSource);
|
|
await Task.Delay(1000);
|
|
}
|
|
}, token));
|
|
});
|
|
}
|
|
|
|
private Task? TimedTask(Func<CancellationTokenSource?, Task>? withOutParamAction = null, Func<TimedtaskInput, Task>? withParemAction = null, CancellationTokenSource? cts = default, TimedtaskInput? parameter = null)
|
|
{
|
|
return parameter != null ? withParemAction?.Invoke(parameter) : withOutParamAction?.Invoke(cts);
|
|
}
|
|
|
|
}
|
|
}
|