public void Execute(BackgroundProcessContext context) { foreach (var table in ProcessedTables) { if (context.CancellationToken.IsCancellationRequested) { return; } _logger.Log($"Removing outdated records from the '{table}' table..."); _storage.UseConnection((conn) => { try { int affected; do { affected = ExecuteNonQuery( conn, GetQuery(_schema, table), context.CancellationToken, new SqlParameter("@count", NumberOfRecordsInSinglePass), new SqlParameter("@now", DateTime.UtcNow)); } while (affected == NumberOfRecordsInSinglePass); } finally { } }); _logger.Log($"Outdated records removed from the '{table}' table."); } context.CancellationToken.WaitHandle.WaitOne(_checkInterval); }