Class DistributedBackgroundService
Extends the Microsoft.Extensions.Hosting.BackgroundService adding a distributed lock mechanism to prevent concurrent executions.
Inheritance
Implements
Inherited Members
Namespace: Silverback.Background
Assembly: Silverback.Core.dll
Syntax
public abstract class DistributedBackgroundService : BackgroundService, IHostedService, IDisposable
Constructors
| Improve this doc View sourceDistributedBackgroundService(DistributedLockSettings, IDistributedLockManager, ISilverbackLogger<DistributedBackgroundService>)
Initializes a new instance of the DistributedBackgroundService class.
Declaration
protected DistributedBackgroundService(DistributedLockSettings distributedLockSettings, IDistributedLockManager distributedLockManager, ISilverbackLogger<DistributedBackgroundService> logger)
Parameters
Type | Name | Description |
---|---|---|
DistributedLockSettings | distributedLockSettings | Customizes the lock mechanism settings. |
IDistributedLockManager | distributedLockManager | |
ISilverbackLogger<DistributedBackgroundService> | logger | The ISilverbackLogger. |
DistributedBackgroundService(IDistributedLockManager, ISilverbackLogger<DistributedBackgroundService>)
Initializes a new instance of the DistributedBackgroundService class using the default settings for the lock mechanism.
Declaration
protected DistributedBackgroundService(IDistributedLockManager distributedLockManager, ISilverbackLogger<DistributedBackgroundService> logger)
Parameters
Type | Name | Description |
---|---|---|
IDistributedLockManager | distributedLockManager | |
ISilverbackLogger<DistributedBackgroundService> | logger | The ISilverbackLogger. |
Properties
| Improve this doc View sourceLock
Gets the acquired DistributedLock.
Declaration
protected DistributedLock Lock { get; }
Property Value
Type | Description |
---|---|
DistributedLock |
Methods
| Improve this doc View sourceExecuteAsync(CancellationToken)
Declaration
protected override Task ExecuteAsync(CancellationToken stoppingToken)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | stoppingToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Overrides
ExecuteLockedAsync(CancellationToken)
This method is called when 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 ExecuteLockedAsync(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. |