---
title: "Task Manager"
slug: "task-manager"
abstract: "Overview of the responsibilities of the Task Manager and how to use it in the context of a core role and in the context of the Processing Engine."
---
# Task Manager

The task manager is responsible for registering tasks to be picked up by agents in the Cortex Processing Engine (Processing Engine). By default, there are two implementations of `ITaskManager`:

- `Sitecore.Processing.Tasks.Messaging.TaskManager` is used by clients such as the Content Management role to register processing tasks via the Message Bus. This implementation is sometimes known as the task manager proxy.
- `Sitecore.Processing.Engine.TaskManager` is used within the Processing Engine to register incoming processing tasks in the Processing Engine Tasks database.

> [!note]
> You should always use the task manager proxy to schedule tasks. Do not use the messaging API directly.

The following example describes the data flow for registering a single distributed task from the Content Management role:

- Use the service locator to get an instance of the `ITaskManager`:

    ```csharp
    var taskManager = ServiceLocator.ServiceProvider.GetService<ITaskManager>();
    ```

<details>
<summary><h2>Using the TaskManager in the context of a core role</h2></summary>

In the context of a core role such as Content Management, use the service locator to get the task manager:

```csharp
var taskManager = ServiceLocator.ServiceProvider.GetService<ITaskManager>();
```

</details>

<details>
<summary><h2>Using the TaskManager in the context of the Processing Engine</h2></summary>

In the context of the Processing Engine, use constructor injection to get an instance of the task manager. The following example shows an instance of `ITaskManager` being injected into a custom message handler:

```csharp
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Sitecore.Framework.Conditions;
using Sitecore.Framework.Messaging;
using Sitecore.Processing.Engine.Abstractions;
using Sitecore.Processing.Engine.Abstractions.Messages;

namespace Sitecore.Documentation.Sample
{
    public abstract class CustomTaskHandler<TRegisterTask> : IMessageHandler<TRegisterTask>
        where TRegisterTask : RegisterTask
    {
        protected CustomTaskHandler(ITaskManager taskManager)
        {
            Condition.Requires(taskManager, nameof(taskManager)).IsNotNull();

            TaskManager = taskManager;
        }
}
```

</details>