Class RecurringTaskBase
Provides a base class for recurring background tasks.
Namespace: Umbraco.Web.Scheduling
Assembly: Umbraco.Web.dll
Syntax
public abstract class RecurringTaskBase : LatchedBackgroundTaskBase, IBackgroundTask, IDisposable
Remarks
Implement by overriding PerformRun or PerformRunAsync and then IsAsync accordingly, depending on whether the task is implemented as a sync or async method. Run nor RunAsync are sealed here as overriding them would break recurrence. And then optionally override RunsOnShutdown, in order to indicate whether the latched task should run immediately on shutdown, or just be abandoned (default).
Constructors
View SourceRecurringTaskBase(IBackgroundTaskRunner<RecurringTaskBase>, Int32, Int32)
Initializes a new instance of the RecurringTaskBase class.
Declaration
protected RecurringTaskBase(IBackgroundTaskRunner<RecurringTaskBase> runner, int delayMilliseconds, int periodMilliseconds)
Parameters
Type | Name | Description |
---|---|---|
IBackgroundTaskRunner<RecurringTaskBase> | runner | The task runner. |
System.Int32 | delayMilliseconds | The delay. |
System.Int32 | periodMilliseconds | The period. |
Remarks
The task will repeat itself periodically. Use this constructor to create a new task.
RecurringTaskBase(IBackgroundTaskRunner<RecurringTaskBase>, Int64, Int64)
Initializes a new instance of the RecurringTaskBase class.
Declaration
protected RecurringTaskBase(IBackgroundTaskRunner<RecurringTaskBase> runner, long delayMilliseconds, long periodMilliseconds)
Parameters
Type | Name | Description |
---|---|---|
IBackgroundTaskRunner<RecurringTaskBase> | runner | The task runner. |
System.Int64 | delayMilliseconds | The delay. |
System.Int64 | periodMilliseconds | The period. |
Remarks
The task will repeat itself periodically. Use this constructor to create a new task.
Methods
View SourceDisposeResources()
Declaration
protected override void DisposeResources()
PerformRun()
Runs the background task.
Declaration
public virtual bool PerformRun()
Returns
Type | Description |
---|---|
System.Boolean | A value indicating whether to repeat the task. |
PerformRunAsync(CancellationToken)
Runs the task asynchronously.
Declaration
public virtual Task<bool> PerformRunAsync(CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | token | A cancellation token. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Boolean> | A System.Threading.Tasks.Task<TResult> instance representing the execution of the background task, and returning a value indicating whether to repeat the task. |
Run()
Implements IBackgroundTask.Run().
Declaration
public sealed override void Run()
Remarks
Classes inheriting from RecurringTaskBase
must implement PerformRun
.
RunAsync(CancellationToken)
Implements IBackgroundTask.RunAsync().
Declaration
public sealed override async Task RunAsync(CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | token |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Remarks
Classes inheriting from RecurringTaskBase
must implement PerformRun
.