Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class Microsoft.​Extensions.​Hosting.​BackgroundService
Assembly: Microsoft.Extensions.Hosting.Abstractions
Inheritance: object → BackgroundService
Implemented Interfaces
Base class for implementing a long running <see cref="T:Microsoft.Extensions.Hosting.IHostedService" /> .
Properties
ExecuteTask
Gets the Task that executes the background operation.
Remarks Will return <see langword="null" /> if the background operation hasn't started.
Methods
public
void
Dispose​()
ExecuteAsync​(System.​Threading.​CancellationToken stoppingToken)
This method is called when the <see cref="T:Microsoft.Extensions.Hosting.IHostedService" /> starts. The implementation should return a task that represents
the lifetime of the long running operation(s) being performed.
Returns A <see cref="T:System.Threading.Tasks.Task" /> that represents the long running operations.
stoppingToken
Triggered when <see cref="M:Microsoft.Extensions.Hosting.IHostedService.StopAsync(System.Threading.CancellationToken)" /> is called.
Remarks
See <see href="https://learn.microsoft.com/dotnet/core/extensions/workers">Worker Services in .NET</see> for implementation guidelines.
StartAsync​(System.​Threading.​CancellationToken cancellationToken)
Triggered when the application host is ready to start the service.
Returns A <see cref="T:System.Threading.Tasks.Task" /> that represents the asynchronous Start operation.
cancellationToken
Indicates that the start process has been aborted.
StopAsync​(System.​Threading.​CancellationToken cancellationToken)
Triggered when the application host is performing a graceful shutdown.
Returns A <see cref="T:System.Threading.Tasks.Task" /> that represents the asynchronous Stop operation.
cancellationToken
Indicates that the shutdown process should no longer be graceful.
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object