public TimedCleaner( ILogger <TimedCleaner> logger, IServiceScopeFactory scopeFactory, TimeoutCleaner timeoutCleaner) { _logger = logger; _scopeFactory = scopeFactory; _timeoutCleaner = timeoutCleaner; }
public void StartCleanerService() { Task.Factory.StartNew(async() => { while (true) { await TimeoutCleaner.AllClean(_dbContext); await Task.Delay(TimeDelay); } }); }
private async void DoWork(object state) { try { _logger.LogInformation("Cleaner task started!"); using (var scope = _scopeFactory.CreateScope()) { var dbContext = scope.ServiceProvider.GetRequiredService <StargateDbContext>(); await TimeoutCleaner.AllClean(dbContext); } } catch (Exception ex) { _logger.LogError(ex, "An error occurred."); } }
private async void DoWork(object state) { await TimeoutCleaner.AllClean(_dbContext); }