Share via


BackgroundService Class

Definition

Base class for implementing a long running IHostedService.

public ref class BackgroundService abstract : IDisposable, Microsoft::Extensions::Hosting::IHostedService
public abstract class BackgroundService : IDisposable, Microsoft.Extensions.Hosting.IHostedService
type BackgroundService = class
    interface IHostedService
    interface IDisposable
Public MustInherit Class BackgroundService
Implements IDisposable, IHostedService
Inheritance
BackgroundService
Implements

Constructors

BackgroundService()

Initializes a new instance of the BackgroundService class.

Properties

ExecuteTask

Gets the Task that executes the background operation.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

ExecuteAsync(CancellationToken)

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.

StartAsync(CancellationToken)

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

StopAsync(CancellationToken)

Triggered when the application host is performing a graceful shutdown.

Extension Methods

StartAndStopAsync(IHostedService, CancellationToken)

Starts and immediately stops the service.

Applies to