Class RecurringHostedServiceBase
Provides a base class for recurring background tasks implemented as hosted services.
Inheritance
Namespace: Umbraco.Cms.Infrastructure.HostedServices
Assembly: Umbraco.Infrastructure.dll
Syntax
public abstract class RecurringHostedServiceBase : IHostedService
Remarks
Constructors
View SourceRecurringHostedServiceBase(Nullable<ILogger>, TimeSpan, TimeSpan)
Initializes a new instance of the Recurring
Declaration
protected RecurringHostedServiceBase(ILogger? logger, TimeSpan period, TimeSpan delay)
Parameters
Type | Name | Description |
---|---|---|
System. |
logger | Logger. |
Time |
period | Timespan representing how often the task should recur. |
Time |
delay | Timespan representing the initial delay after application start-up before the first run of the task occurs. |
Fields
View SourceDefaultDelay
The default delay to use for recurring tasks for the first run after application start-up if no alternative is configured.
Declaration
protected static readonly TimeSpan DefaultDelay
Field Value
Type | Description |
---|---|
Time |
Methods
View SourceChangePeriod(TimeSpan)
Change the period between operations.
Declaration
protected void ChangePeriod(TimeSpan newPeriod)
Parameters
Type | Name | Description |
---|---|---|
Time |
newPeriod | The new period between tasks |
Dispose()
Declaration
public void Dispose()
Dispose(Boolean)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System. |
disposing |
ExecuteAsync(Object)
Executes the task.
Declaration
public virtual async void ExecuteAsync(object state)
Parameters
Type | Name | Description |
---|---|---|
System. |
state | The task state. |
GetDelay(String, ICronTabParser, ILogger, TimeSpan)
Determines the delay before the first run of a recurring task implemented as a hosted service when an optonal configuration for the first run time is available.
Declaration
protected static TimeSpan GetDelay(string firstRunTime, ICronTabParser cronTabParser, ILogger logger, TimeSpan defaultDelay)
Parameters
Type | Name | Description |
---|---|---|
System. |
firstRunTime | The configured time to first run the task in crontab format. |
ICron |
cronTabParser | An instance of ICron |
ILogger | logger | The logger. |
Time |
defaultDelay | The default delay to use when a first run time is not configured. |
Returns
Type | Description |
---|---|
Time |
The delay before first running the recurring task. |
PerformExecuteAsync(Object)
Declaration
public abstract Task PerformExecuteAsync(object state)
Parameters
Type | Name | Description |
---|---|---|
System. |
state |
Returns
Type | Description |
---|---|
Task |
StartAsync(CancellationToken)
Declaration
public virtual Task StartAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Cancellation |
cancellationToken |
Returns
Type | Description |
---|---|
Task |
StopAsync(CancellationToken)
Declaration
public virtual Task StopAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Cancellation |
cancellationToken |
Returns
Type | Description |
---|---|
Task |