using NewLife.Log; using NewLife.Threading; using WorkerSynReport.Plc; namespace WorkerSynReport; public class PclWorker:BackgroundService { private readonly IServiceScopeFactory _scopeFactory; private readonly ILogger _logger; TimerX? _timer; public PclWorker(ILogger 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(); // // readDb?.ReadReport(); // readDb?.ReadFeededDry(); } }