예제 #1
0
 public TimedCleaner(
     ILogger <TimedCleaner> logger,
     IServiceScopeFactory scopeFactory,
     TimeoutCleaner timeoutCleaner)
 {
     _logger         = logger;
     _scopeFactory   = scopeFactory;
     _timeoutCleaner = timeoutCleaner;
 }
예제 #2
0
 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.");
     }
 }
예제 #4
0
 private async void DoWork(object state)
 {
     await TimeoutCleaner.AllClean(_dbContext);
 }