// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 namespace TestApplication.Worker; public class Worker : BackgroundService { private readonly ILogger _logger; private readonly IHostApplicationLifetime _hostApplicationLifetime; public Worker(ILogger logger, IHostApplicationLifetime hostApplicationLifetime) { _logger = logger; _hostApplicationLifetime = hostApplicationLifetime; } protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogInformation("Worker running."); await Task.Delay(1000, stoppingToken); // When completed, the entire app host will stop. _hostApplicationLifetime.StopApplication(); } }