protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { if (_dbContext == null) { var scope = _scopeFactory.CreateScope(); _dbContext = scope.ServiceProvider.GetRequiredService <OnlineExaminationSystemContext>(); } var finishedExams = await _dbContext.Exams .Where(exam => !exam.IsFinished).ToListAsync(); foreach (var exam in finishedExams) { // bir şeyler yap! exam.IsFinished = true; } if (_dbContext.ChangeTracker.HasChanges()) { await _dbContext.SaveChangesAsync(); } _logger.LogInformation("Worker Service is running!"); await Task.Delay(1000, stoppingToken); } }