You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB
C#

using NewLife.Log;
using NewLife.Threading;
using WorkerSynReport.Plc;
namespace WorkerSynReport;
public class PclWorker:BackgroundService
{
private readonly IServiceScopeFactory _scopeFactory;
private readonly ILogger<PclWorker> _logger;
TimerX? _timer;
public PclWorker(ILogger<PclWorker> logger, IServiceScopeFactory scopeFactory)
{
_logger = logger;
this._scopeFactory = scopeFactory;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_timer ??= new TimerX(DoPlc, "", 100, 1000);
_timer.Async = true;
// while (!stoppingToken.IsCancellationRequested)
// {
//
// await Task.Delay(1000, stoppingToken);
// }
}
private void DoPlc(Object state)
{
_logger.LogInformation("{Data}",DateTime.Now.ToFullString());
//todo 备份数据库
// using var scope = _scopeFactory.CreateScope();
// var services = scope.ServiceProvider;
// ReportReadDb? readDb = services.GetService<ReportReadDb>();
//
// readDb?.ReadReport();
// readDb?.ReadFeededDry();
}
}