BackgroundService.ExecuteAsync(CancellationToken) Method

Definition

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.

C#
protected abstract System.Threading.Tasks.Task ExecuteAsync (System.Threading.CancellationToken stoppingToken);

Parameters

stoppingToken
CancellationToken

Triggered when StopAsync(CancellationToken) is called.

Returns

A Task that represents the long running operations.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

See Worker Services in .NET for implementation guidelines.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 4.7 (package-provided), 4.7.1 (package-provided), 4.7.2 (package-provided), 4.8 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)