Table of Contents

Class RecurringDistributedBackgroundService

Namespace
Silverback.Background
Assembly
Silverback.Core.dll

Extends the DistributedBackgroundService calling the execute method at regular intervals. The distributed lock mechanism prevents concurrent executions.

public abstract class RecurringDistributedBackgroundService : DistributedBackgroundService, IHostedService, IDisposable
Inheritance
RecurringDistributedBackgroundService
Implements
Derived
Inherited Members

Constructors

RecurringDistributedBackgroundService(TimeSpan, IDistributedLock, ISilverbackLogger<RecurringDistributedBackgroundService>)

Initializes a new instance of the RecurringDistributedBackgroundService class.

protected RecurringDistributedBackgroundService(TimeSpan interval, IDistributedLock distributedLock, ISilverbackLogger<RecurringDistributedBackgroundService> logger)

Parameters

interval TimeSpan

The TimeSpan interval between each execution.

distributedLock IDistributedLock

The IDistributedLock.

logger ISilverbackLogger<RecurringDistributedBackgroundService>

The ISilverbackLogger.

Methods

AcquireLockAndExecuteAsync(CancellationToken)

Acquires the lock and calls the ExecuteLockedAsync(CancellationToken) method to perform the operation(s).

protected override Task AcquireLockAndExecuteAsync(CancellationToken stoppingToken)

Parameters

stoppingToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task

A Task representing the asynchronous operation.

Pause()

Pauses the execution of the recurring task.

public void Pause()

Resume()

Resumes the execution of the previously paused recurring task.

public void Resume()