protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogInformation("Starting hosted service {Service}", nameof(StatsBackgroundService)); while (!stoppingToken.IsCancellationRequested) { try { IPage <BlockDto> blocks = await _apiService.GetBlocks(1, 20, SortOrder.Descending).ConfigureAwait(false); await _blockService.UpdateRecentBlocks(blocks.Items).ConfigureAwait(false); IPage <TransactionDto> transactions = await _apiService.GetTransactions(1, 20, SortOrder.Descending).ConfigureAwait(false); await _transactionService.UpdateRecentTransactions(transactions.Items).ConfigureAwait(false); } catch (Exception e) { _logger.LogError(e, "{Class} -> {Method} -> When getting recent blocks", nameof(StatsBackgroundService), nameof(ExecuteAsync)); await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken).ConfigureAwait(false); } await Task.Delay(TimeSpan.FromSeconds(15), stoppingToken).ConfigureAwait(false); } }