private void DoWork(object state) { var expired = tempFilesRepository.GetExpired(); if (!expired.Any()) { return; } foreach (var file in expired) { fileProvider.DeleteTempFile(file.FileName); } var last = expired.Last(); tempFilesRepository.ClearUntil(last.Expiration); }