Class RecurringDistributedBackgroundService
Extends the DistributedBackgroundService calling the execute method at regular intervals. The distributed lock mechanism prevents concurrent executions.
Inheritance
RecurringDistributedBackgroundService
Inherited Members
Namespace: Silverback.Background
Assembly: Silverback.Core.dll
Syntax
public abstract class RecurringDistributedBackgroundService : DistributedBackgroundService, IHostedService, IDisposable
Constructors
RecurringDistributedBackgroundService(TimeSpan, IDistributedLock, ISilverbackLogger<RecurringDistributedBackgroundService>)
Initializes a new instance of the RecurringDistributedBackgroundService class.
Declaration
protected RecurringDistributedBackgroundService(TimeSpan interval, IDistributedLock distributedLock, ISilverbackLogger<RecurringDistributedBackgroundService> logger)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | interval | The TimeSpan interval between each execution. |
| IDistributedLock | distributedLock | The IDistributedLock. |
| ISilverbackLogger<RecurringDistributedBackgroundService> | logger | The ISilverbackLogger. |
Methods
AcquireLockAndExecuteAsync(CancellationToken)
Acquires the lock and calls the ExecuteLockedAsync(CancellationToken) method to perform the operation(s).
Declaration
protected override Task AcquireLockAndExecuteAsync(CancellationToken stoppingToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | stoppingToken | A CancellationToken to observe while waiting for the task to complete. |
Returns
| Type | Description |
|---|---|
| Task | A Task representing the asynchronous operation. |
Overrides
Pause()
Pauses the execution of the recurring task.
Declaration
public void Pause()
Resume()
Resumes the execution of the previously paused recurring task.
Declaration
public void Resume()