Table of Contents

Class BackgroundService

Namespace
Microsoft.Extensions.Hosting
Assembly
nanoFramework.Hosting.dll

Base class for implementing a long running IHostedService.

public abstract class BackgroundService : IHostedService, IDisposable
Inheritance
BackgroundService
Implements
Inherited Members
Extension Methods

Constructors

BackgroundService()

protected BackgroundService()

Properties

ShutdownTimeout

Gets or sets the amount of time to wait for the ExecuteThread() to terminate.

protected TimeSpan ShutdownTimeout { get; set; }

Property Value

TimeSpan

Methods

Dispose()

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

public void Dispose()

Dispose(bool)

Releases the unmanaged resources used by the BackgroundService and optionally releases the managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks

If you override this method in a derived class, be sure to call the base class's Dispose(bool) method.

ExecuteAsync(CancellationToken)

This method is called when the IHostedService starts.

protected abstract void ExecuteAsync(CancellationToken stoppingToken)

Parameters

stoppingToken CancellationToken

Triggered when StopAsync(CancellationToken) is called.

Remarks

See Worker Services in .NET for implementation guidelines.

ExecuteThread()

Gets the Thread that executes the background operation.

public virtual Thread? ExecuteThread()

Returns

Thread

Remarks

Will return null if the background operation hasn't started.

Finalize()

protected override void Finalize()

StartAsync(CancellationToken)

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

public virtual void StartAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Indicates that the start process has been aborted.

StopAsync(CancellationToken)

Triggered when the application host is performing a graceful shutdown.

public virtual void StopAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Indicates that the shutdown process should no longer be graceful.