WMS新增,自定义定时任务
This commit is contained in:
47
WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs
Normal file
47
WarehouseMgr/Tnb.WarehouseMgr/TimedTaskBackgroundService.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user