Class RecurringDistributedBackgroundService
Extends the DistributedBackgroundService calling the execute method at regular intervals. The distributed lock mechanism prevents concurrent executions.
Inheritance
Implements
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 |
---|---|---|
System.TimeSpan | interval | The System.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 |
---|---|---|
System.TimeSpan | interval | The interval between each execution. |
IDistributedLockManager | distributedLockManager | |
ISilverbackLogger<RecurringDistributedBackgroundService> | logger | The ISilverbackLogger. |
Methods
| Improve this doc View sourceExecuteLockedAsync(CancellationToken)
Declaration
protected override async Task ExecuteLockedAsync(CancellationToken stoppingToken)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | stoppingToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Overrides
| Improve this doc View sourceExecuteRecurringAsync(CancellationToken)
This method is called at regular intervals after the Microsoft.Extensions.Hosting.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 |
---|---|---|
System.Threading.CancellationToken | stoppingToken | A System.Threading.CancellationToken to observe while waiting for the task to complete. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A System.Threading.Tasks.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()