using NewLife.Log; using NewLife.Threading; namespace WorkerSynReport; public class ReportReadBackgroud:BackgroundService { private readonly ILogger _logger; private TimerX _timer; private readonly IServiceScopeFactory _scopeFactory; public ReportReadBackgroud(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; } private void DoPlc(Object state) { try { ReportReadDb.ReadReport(); } catch (Exception e) { XTrace.WriteException(e); } } }