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 RecurringHostedServiceBase class.
Declaration
protected RecurringHostedServiceBase(ILogger? logger, TimeSpan period, TimeSpan delay)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<ILogger> | logger | Logger. |
TimeSpan | period | Timespan representing how often the task should recur. |
TimeSpan | 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 |
---|---|
TimeSpan |
Methods
View SourceChangePeriod(TimeSpan)
Change the period between operations.
Declaration
protected void ChangePeriod(TimeSpan newPeriod)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | 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.Boolean | disposing |
ExecuteAsync(Object)
Executes the task.
Declaration
public async void ExecuteAsync(object state)
Parameters
Type | Name | Description |
---|---|---|
System.Object | 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.String | firstRunTime | The configured time to first run the task in crontab format. |
ICronTabParser | cronTabParser | An instance of ICronTabParser |
ILogger | logger | The logger. |
TimeSpan | defaultDelay | The default delay to use when a first run time is not configured. |
Returns
Type | Description |
---|---|
TimeSpan | The delay before first running the recurring task. |
PerformExecuteAsync(Object)
Declaration
public abstract Task PerformExecuteAsync(object state)
Parameters
Type | Name | Description |
---|---|---|
System.Object | state |
Returns
Type | Description |
---|---|
Task |
StartAsync(CancellationToken)
Declaration
public Task StartAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
StopAsync(CancellationToken)
Declaration
public Task StopAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |