<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="11.0.0-preview.7.26381.103" />

Microsoft.Extensions.Hosting.BackgroundService

public abstract class BackgroundService : IHostedService, IDisposable
Base class for implementing a long running IHostedService.
public virtual Task ExecuteTask { get; }

Gets the Task that executes the background operation.

protected BackgroundService()

public virtual void Dispose()

protected abstract Task ExecuteAsync(CancellationToken stoppingToken)

This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.

public virtual Task StartAsync(CancellationToken cancellationToken)

Triggered when the application host is ready to start the service.

public virtual Task StopAsync(CancellationToken cancellationToken)

Triggered when the application host is performing a graceful shutdown.