<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.9" />

Microsoft.Extensions.Hosting.IHostedLifecycleService

Defines methods that are run before or after StartAsync and StopAsync.
Task StartedAsync(CancellationToken cancellationToken)

Triggered after StartAsync.

Triggered before StartAsync.

Task StoppedAsync(CancellationToken cancellationToken)

Triggered after StopAsync.

Triggered before StopAsync.