Table of Contents

Class ApplicationBackgroundService

Namespace
CMS.DataEngine
Assembly
CMS.DataEngine.dll

Base class for implementing background tasks in Kentico.

[Obsolete("Use ApplicationLifecycleBackgroundService instead.")]
public abstract class ApplicationBackgroundService : ApplicationLifecycleBackgroundService
Inheritance
object
BackgroundService
ApplicationBackgroundService
Inherited Members
Extension Methods

Remarks

This class extends the native Microsoft.Extensions.Hosting.BackgroundService class and ensures that background tasks are executed only after the application is initialized and started.. It provides the ability to override all methods from the Microsoft.Extensions.Hosting.BackgroundService class, but doing so may change the behavior of the service.

Additionally, it includes a mechanism for restarting the service in case of an uncaught exception. The desired logic of a background service should be implemented in the ExecuteInternal(CancellationToken) method. If there is a need to make the logic recurring, it must be handled also in the body of the ExecuteInternal(CancellationToken) method. This base class does not provide any recurring logic by default.

Furthermore, it maintains thread context separation by ensuring a fresh context scope for each background service instance. This means that each background service instance is assigned its own connection scope.

Constructors

ApplicationBackgroundService()

Initializes a new instance of the ApplicationBackgroundService class.

public ApplicationBackgroundService()

See Also