Class BackgroundTaskRunner<T>
Manages a queue of tasks of type T
and runs them in the background.
Namespace: Umbraco.Web.Scheduling
Assembly: Umbraco.Web.dll
Syntax
public class BackgroundTaskRunner<T> : BackgroundTaskRunner, IBackgroundTaskRunner<T>, IDisposable, IRegisteredObject where T : class, IBackgroundTask
Type Parameters
Name | Description |
---|---|
T | The type of the managed tasks. |
Remarks
The task runner is web-aware and will ensure that it shuts down correctly when the AppDomain shuts down (ie is unloaded).
Constructors
View SourceBackgroundTaskRunner(String, ILogger, BackgroundTaskRunner.MainDomHook)
Initializes a new instance of the BackgroundTaskRunner<T> class.
Declaration
public BackgroundTaskRunner(string name, ILogger logger, BackgroundTaskRunner.MainDomHook hook = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
name | The name of the runner. |
ILogger | logger | A logger. |
Background |
hook | An optional main domain hook. |
BackgroundTaskRunner(String, BackgroundTaskRunnerOptions, ILogger, BackgroundTaskRunner.MainDomHook)
Initializes a new instance of the BackgroundTaskRunner<T> class with a set of options.
Declaration
public BackgroundTaskRunner(string name, BackgroundTaskRunnerOptions options, ILogger logger, BackgroundTaskRunner.MainDomHook hook = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
name | The name of the runner. |
Background |
options | The set of options. |
ILogger | logger | A logger. |
Background |
hook | An optional main domain hook. |
BackgroundTaskRunner(ILogger, BackgroundTaskRunner.MainDomHook)
Initializes a new instance of the BackgroundTaskRunner<T> class.
Declaration
public BackgroundTaskRunner(ILogger logger, BackgroundTaskRunner.MainDomHook hook = null)
Parameters
Type | Name | Description |
---|---|---|
ILogger | logger | A logger. |
Background |
hook | An optional main domain hook. |
BackgroundTaskRunner(BackgroundTaskRunnerOptions, ILogger, BackgroundTaskRunner.MainDomHook)
Initializes a new instance of the BackgroundTaskRunner<T> class with a set of options.
Declaration
public BackgroundTaskRunner(BackgroundTaskRunnerOptions options, ILogger logger, BackgroundTaskRunner.MainDomHook hook = null)
Parameters
Type | Name | Description |
---|---|---|
Background |
options | The set of options. |
ILogger | logger | A logger. |
Background |
hook | An optional main domain hook. |
Properties
View SourceIsCompleted
Gets a value indicating whether the runner has completed and cannot accept tasks anymore.
Declaration
public bool IsCompleted { get; }
Property Value
Type | Description |
---|---|
System. |
IsDisposed
Declaration
public bool IsDisposed { get; }
Property Value
Type | Description |
---|---|
System. |
IsRunning
Gets a value indicating whether a threading task is currently running.
Declaration
public bool IsRunning { get; }
Property Value
Type | Description |
---|---|
System. |
StoppedAwaitable
Gets an awaitable used to await the runner running operation.
Declaration
public ThreadingTaskImmutable StoppedAwaitable { get; }
Property Value
Type | Description |
---|---|
Threading |
An awaitable instance. |
Remarks
Used to wait until the runner is no longer running (IsRunning == false), though the runner could be started again afterwards by adding tasks to it. If the runner is not running, returns a completed awaitable.
TaskCount
Gets the number of tasks in the queue.
Declaration
public int TaskCount { get; }
Property Value
Type | Description |
---|---|
System. |
Methods
View SourceAdd(T)
Adds a task to the queue.
Declaration
public void Add(T task)
Parameters
Type | Name | Description |
---|---|---|
T | task | The task to add. |
Exceptions
Type | Condition |
---|---|
System. |
The task runner has completed. |
CancelCurrentBackgroundTask()
Cancels to current task, if any.
Declaration
public void CancelCurrentBackgroundTask()
Remarks
Has no effect if the task runs synchronously, or does not want to cancel.
Dispose()
Declaration
public void Dispose()
Dispose(Boolean)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System. |
disposing |
DisposeResources()
Declaration
protected virtual void DisposeResources()
Finalize()
Declaration
protected void Finalize()
OnTaskCancelled(TaskEventArgs<T>)
Declaration
protected virtual void OnTaskCancelled(TaskEventArgs<T> e)
Parameters
Type | Name | Description |
---|---|---|
Task |
e |
OnTaskCompleted(TaskEventArgs<T>)
Declaration
protected virtual void OnTaskCompleted(TaskEventArgs<T> e)
Parameters
Type | Name | Description |
---|---|---|
Task |
e |
OnTaskError(TaskEventArgs<T>)
Declaration
protected virtual void OnTaskError(TaskEventArgs<T> e)
Parameters
Type | Name | Description |
---|---|---|
Task |
e |
OnTaskStarting(TaskEventArgs<T>)
Declaration
protected virtual void OnTaskStarting(TaskEventArgs<T> e)
Parameters
Type | Name | Description |
---|---|---|
Task |
e |
Shutdown(Boolean, Boolean)
Shuts the tasks runner down.
Declaration
public void Shutdown(bool force, bool wait)
Parameters
Type | Name | Description |
---|---|---|
System. |
force | True for force the runner to stop. |
System. |
wait | True to wait until the runner has stopped. |
Remarks
If force
is false, no more tasks can be queued but all queued tasks
will run. If it is true, then only the current one (if any) will end and no other task will run.
Stop(Boolean)
Requests a registered object to un-register.
Declaration
public void Stop(bool immediate)
Parameters
Type | Name | Description |
---|---|---|
System. |
immediate | true to indicate the registered object should un-register from the hosting environment before returning; otherwise, false. |
Remarks
"When the application manager needs to stop a registered object, it will call the Stop method."
The application manager will call the Stop method to ask a registered object to un-register. During processing of the Stop method, the registered object must call the HostingEnvironment.UnregisterObject method.
TryAdd(T)
Tries to add a task to the queue.
Declaration
public bool TryAdd(T task)
Parameters
Type | Name | Description |
---|---|---|
T | task | The task to add. |
Returns
Type | Description |
---|---|
System. |
true if the task could be added to the queue; otherwise false. |
Remarks
Returns false if the runner is completed.
Events
View SourceTaskCancelled
Declaration
public event TypedEventHandler<BackgroundTaskRunner<T>, TaskEventArgs<T>> TaskCancelled
Event Type
Type | Description |
---|---|
Typed |
TaskCompleted
Declaration
public event TypedEventHandler<BackgroundTaskRunner<T>, TaskEventArgs<T>> TaskCompleted
Event Type
Type | Description |
---|---|
Typed |
TaskError
Declaration
public event TypedEventHandler<BackgroundTaskRunner<T>, TaskEventArgs<T>> TaskError
Event Type
Type | Description |
---|---|
Typed |
TaskStarting
Declaration
public event TypedEventHandler<BackgroundTaskRunner<T>, TaskEventArgs<T>> TaskStarting
Event Type
Type | Description |
---|---|
Typed |