30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
|
using ConsoleApp2.HostedServices.Abstractions;
|
|||
|
using Microsoft.Extensions.Hosting;
|
|||
|
|
|||
|
namespace ConsoleApp2.HostedServices;
|
|||
|
|
|||
|
public class MainHostedService : BackgroundService
|
|||
|
{
|
|||
|
private readonly IInputService _input;
|
|||
|
private readonly ITransformService _transform;
|
|||
|
private readonly IOutputService _output;
|
|||
|
|
|||
|
public MainHostedService(IInputService input, ITransformService transform, IOutputService output)
|
|||
|
{
|
|||
|
_input = input;
|
|||
|
_transform = transform;
|
|||
|
_output = output;
|
|||
|
}
|
|||
|
|
|||
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|||
|
{
|
|||
|
var tasks = new List<Task>()
|
|||
|
{
|
|||
|
Task.Run(async () => await _input.ExecuteAsync(stoppingToken), stoppingToken),
|
|||
|
Task.Run(async () => await _transform.ExecuteAsync(stoppingToken), stoppingToken),
|
|||
|
Task.Run(async () => await _output.ExecuteAsync(stoppingToken), stoppingToken),
|
|||
|
};
|
|||
|
await Task.WhenAll(tasks);
|
|||
|
// await Task.Run(async () => await _output.ExecuteAsync(stoppingToken), stoppingToken);
|
|||
|
}
|
|||
|
}
|