Interface IBackgroundTaskManager

Manages safe execution of background tasks, and exposes progress messages from the tasks.

Namespace: Mediachase.Commerce.BackgroundTasks
Assembly: Mediachase.Commerce.dll
Version: 10.8.0
Syntax
public interface IBackgroundTaskManager

Methods

AddTask(IBackgroundTask)

Adds a task for the manager to run. The task will be executed immediately if no other tasks are running, or queued if another task is active.

Declaration
Guid AddTask(IBackgroundTask task)
Parameters
Type Name Description
IBackgroundTask task

The task to execute.

Returns
Type Description
System.Guid

The ID of the new task.

GetMessages(Guid)

Gets the messages generated by the specified task. Messages will be returned in same order they were created.

Declaration
IList<IBackgroundTaskMessage> GetMessages(Guid taskId)
Parameters
Type Name Description
System.Guid taskId

The ID of the task to query.

Returns
Type Description
System.Collections.Generic.IList<IBackgroundTaskMessage>

A collection of messages generated by the specified task.

Exceptions
Type Condition
System.ArgumentException

The specified task ID was not found.

GetMessages(Guid, Int32, Int32, out Int32, IEnumerable<BackgroundTaskMessageType>)

Gets the messages generated by the specified task, with paging. Messages will be paged by and returned in the same order they were created.

Declaration
IList<IBackgroundTaskMessage> GetMessages(Guid taskId, int offset, int count, out int totalCount, IEnumerable<BackgroundTaskMessageType> messageTypeFilter = null)
Parameters
Type Name Description
System.Guid taskId

The ID of the task to query.

System.Int32 offset

The number of messages to skip.

System.Int32 count

The maximum number of messages to return.

System.Int32 totalCount

Set to the total number of messages generated by the specified task.

System.Collections.Generic.IEnumerable<BackgroundTaskMessageType> messageTypeFilter

If non-null, only message types contained in the filter will be returned; if null, all message tyeps will be returned.

Returns
Type Description
System.Collections.Generic.IList<IBackgroundTaskMessage>

A collection of messages generated by the specified task.

Exceptions
Type Condition
System.ArgumentException

The specified task ID was not found.

GetProgress(Guid)

Gets the most recent message generated by the specified task, or null if the task has not generated any messages.

Declaration
IBackgroundTaskMessage GetProgress(Guid taskId)
Parameters
Type Name Description
System.Guid taskId

The ID of the task to query.

Returns
Type Description
IBackgroundTaskMessage

The most recent message, or null if the task has not generated any messages.

Exceptions
Type Condition
System.ArgumentException

The specified task ID was not found.

QueryTasks(IEnumerable<Guid>, IEnumerable<Type>, IEnumerable<BackgroundTaskStatus>)

Queries the task manager for known tasks.

Declaration
IList<BackgroundTaskState> QueryTasks(IEnumerable<Guid> taskIds = null, IEnumerable<Type> taskTypes = null, IEnumerable<BackgroundTaskStatus> taskStatuses = null)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Guid> taskIds

Only return tasks with the specified task IDs; or if null, do not filter by task ID.

System.Collections.Generic.IEnumerable<System.Type> taskTypes

Only return tasks with the specified task types; or if null, do not filter by task type.

System.Collections.Generic.IEnumerable<BackgroundTaskStatus> taskStatuses

Only return tasks with the specified task status; or if null, do not filter by task status.

Returns
Type Description
System.Collections.Generic.IList<BackgroundTaskState>

A collection of tasks matching the specified filters.