Class RecurringDistributedBackgroundService
Extends the DistributedBackgroundService calling the execute method at regular intervals. The distributed lock mechanism prevents concurrent executions.
Inheritance
Inherited Members
Namespace: Silverback.Background
Assembly: Silverback.Core.dll
Syntax
public abstract class RecurringDistributedBackgroundService : DistributedBackgroundService, IHostedService, IDisposable
Constructors
| Improve this doc View sourceRecurringDistributedBackgroundService(TimeSpan, DistributedLockSettings?, IDistributedLockManager, ISilverbackLogger<RecurringDistributedBackgroundService>)
Initializes a new instance of the RecurringDistributedBackgroundService class.
Declaration
protected RecurringDistributedBackgroundService(TimeSpan interval, DistributedLockSettings? distributedLockSettings, IDistributedLockManager distributedLockManager, ISilverbackLogger<RecurringDistributedBackgroundService> logger)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | interval | The TimeSpan interval between each execution. |
DistributedLockSettings | distributedLockSettings | Customizes the lock mechanism settings. |
IDistributedLockManager | distributedLockManager | |
ISilverbackLogger<RecurringDistributedBackgroundService> | logger | The ISilverbackLogger. |
RecurringDistributedBackgroundService(TimeSpan, IDistributedLockManager, ISilverbackLogger<RecurringDistributedBackgroundService>)
Initializes a new instance of the RecurringDistributedBackgroundService class using the default settings for the lock mechanism.
Declaration
protected RecurringDistributedBackgroundService(TimeSpan interval, IDistributedLockManager distributedLockManager, ISilverbackLogger<RecurringDistributedBackgroundService> logger)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | interval | The interval between each execution. |
IDistributedLockManager | distributedLockManager | |
ISilverbackLogger<RecurringDistributedBackgroundService> | logger | The ISilverbackLogger. |
Methods
| Improve this doc View sourceExecuteLockedAsync(CancellationToken)
This method is called when the IHostedService starts and the lock is acquired. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.
Declaration
protected override Task ExecuteLockedAsync(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 that represents the long running operations. |
Overrides
| Improve this doc View sourceExecuteRecurringAsync(CancellationToken)
This method is called at regular intervals after the IHostedService starts and the lock is acquired. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.
Declaration
protected abstract Task ExecuteRecurringAsync(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 that represents the long running operations. |
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()