Update
This commit is contained in:
30
ConsoleApp2/HostedServices/MainHostedService.cs
Normal file
30
ConsoleApp2/HostedServices/MainHostedService.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user