[Canonical page](<https://docs.dhtmlx.com/planning-engine/net/scheduling/critical-path-and-slack/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# Critical path and slack

This guide shows how to find the tasks that set the project's finish date and how much room every other task has. You can get these numbers from a scheduling run, or from dates you already have without scheduling anything.

## How analytics work

Analytics are off by default. Ask for them with an [`AnalyticsOptions`](<https://docs.dhtmlx.com/planning-engine/net/api/core/project/analytics-options.md>) value. It has two flags, `CriticalPath` and `Slack`, and you can pass it in three places:

- [`SolveOptions.Analytics`](<https://docs.dhtmlx.com/planning-engine/net/api/core/project/solve-options.md#analytics>), for [`Engine.Schedule`](<https://docs.dhtmlx.com/planning-engine/net/api/engine-schedule.md>) and [`Project.Solve`](<https://docs.dhtmlx.com/planning-engine/net/api/project-solve.md>). The analytics describe the freshly scheduled dates.
- [`PreviewOptions.Analytics`](<https://docs.dhtmlx.com/planning-engine/net/api/core/project/preview-options.md#analytics>), for [`Project.Preview`](<https://docs.dhtmlx.com/planning-engine/net/api/project-preview.md>). The analytics describe the previewed dates.
- [`AnalyzeOptions.Analytics`](<https://docs.dhtmlx.com/planning-engine/net/api/core/project/analyze-options.md#analytics>), for [`Project.Analyze`](<https://docs.dhtmlx.com/planning-engine/net/api/project-analyze.md>). The analytics describe dates you supply, or the project's current dates, as they are. Nothing gets scheduled.

When you set at least one flag, [`ScheduleResult.Analytics`](<https://docs.dhtmlx.com/planning-engine/net/api/core/results/schedule-result.md#analytics>) holds an [`Analytics`](<https://docs.dhtmlx.com/planning-engine/net/api/core/results/analytics.md>) object. With both flags off, it's `null`.

The engine works from two plans. The first plan is the dates being analyzed. For the second, the engine schedules the same tasks backward from the latest finish, which gives each task its latest possible start. Slack is the gap between the two:

- **Total slack** is how far a task can slip before the project's finish date moves. It's the latest start minus the planned start.
- **Free slack** is how far a task can slip before it pushes any successor. It's the smallest margin over the task's outgoing links, and never more than the total slack. A task with no successors has free slack equal to its total slack.

A task is **critical** when its total slack is zero or less. A link is critical when both of its tasks are critical and the link is binding, which means its target starts exactly when the link allows. `Analytics.CriticalPath` is a [`Critical`](<https://docs.dhtmlx.com/planning-engine/net/api/core/results/analytics.md#critical>) object with the critical task ids in `Tasks` and the link ids in `Links`. `Analytics.Slack` holds one [`TaskSlack`](<https://docs.dhtmlx.com/planning-engine/net/api/core/results/analytics.md#taskslack>) per task, with `Task`, `Total` and `Free`.

A few rules shape the output:

- Slack is a `double` in the configured [`DurationUnit`](<https://docs.dhtmlx.com/planning-engine/net/api/core/data/scheduling-config.md#durationunit>) (days by default) and counts working time on each task's calendar. A weekend between two tasks doesn't add slack.
- Only leaf tasks and milestones get a slack entry. A summary has no slack. It's critical when any of its non-summary descendants is.
- With [`UseProgress`](<https://docs.dhtmlx.com/planning-engine/net/api/core/data/scheduling-config.md#useprogress>), completed tasks (`Progress == 1`) report zero total and free slack, but they're never critical.
- A dependency cycle makes the numbers meaningless. `Status` is then [`AnalyticsStatus.Invalid`](<https://docs.dhtmlx.com/planning-engine/net/api/core/results/analytics.md#analyticsstatus>), and `CriticalPath` and `Slack` are both `null`.

## Getting critical path and slack

### Requesting analytics

Set the flags in [`SolveOptions`](<https://docs.dhtmlx.com/planning-engine/net/api/core/project/solve-options.md>) to get analytics together with the schedule.

```csharp
using Plen;

var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");

var data = new ProjectData
{
    Tasks =
    [
        new TaskData("design") { StartDate = monday, Duration = 2.0 },
        new TaskData("build") { StartDate = monday, Duration = 3.0 },
        new TaskData("docs") { StartDate = monday, Duration = 1.0 },
    ],
    Links =
    [
        new LinkData { Id = "l1", Source = "design", Target = "build" },
        new LinkData { Id = "l2", Source = "design", Target = "docs" },
    ],
};

var options = new SolveOptions
{
    Analytics = new AnalyticsOptions { CriticalPath = true, Slack = true },
};
var result = Engine.Schedule(data, options);

var analytics = result.Analytics ?? throw new InvalidOperationException("analytics not requested");
if (analytics.CriticalPath is { } critical)
{
    foreach (var id in critical.Tasks)
        Console.WriteLine($"critical task: {id}");
    foreach (var id in critical.Links)
        Console.WriteLine($"critical link: {id}");
}
foreach (var s in analytics.Slack ?? [])
    Console.WriteLine($"{s.Task}: total {s.Total} free {s.Free}");
```

`build` and `docs` both wait for `design`. `build` takes three days and `docs` takes one, so `design` and `build` form the critical path, joined by link `l1`. `docs` reports `total 2 free 2`: it can slip two working days before the project end moves.

[`Project.Solve`](<https://docs.dhtmlx.com/planning-engine/net/api/project-solve.md>) takes the same `SolveOptions`. The cache key for `Solve(null, …)` is the whole `SolveOptions` value, so turning analytics on recomputes from the accepted dates. You don't get back a cached result that lacks them.

### Checking a change before you commit it

Set the flags in [`PreviewOptions`](<https://docs.dhtmlx.com/planning-engine/net/api/core/project/preview-options.md>) to see how an edit would change the critical path.

```csharp
using Plen;

var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");

var data = new ProjectData
{
    Tasks =
    [
        new TaskData("design") { StartDate = monday, Duration = 2.0 },
        new TaskData("build") { StartDate = monday, Duration = 3.0 },
        new TaskData("docs") { StartDate = monday, Duration = 1.0 },
    ],
    Links =
    [
        new LinkData { Id = "l1", Source = "design", Target = "build" },
        new LinkData { Id = "l2", Source = "design", Target = "docs" },
    ],
};

var project = new Project();
project.Solve(data, new SolveOptions());

// What if the docs take five days instead of one?
var changes = new SchedulingChanges();
changes.Tasks.Update.Add(new TaskUpdate("docs") { Duration = 5.0 });

var options = new PreviewOptions
{
    Analytics = new AnalyticsOptions { CriticalPath = true, Slack = true },
};
var result = project.Preview(changes, options);

var analytics = result.Analytics ?? throw new InvalidOperationException("analytics not requested");
if (analytics.CriticalPath is { } critical)
    Console.WriteLine($"critical: {string.Join(", ", critical.Tasks)}");
foreach (var s in analytics.Slack ?? [])
    Console.WriteLine($"{s.Task}: total {s.Total} free {s.Free}");
```

With five days of docs, the critical path moves to `design, docs`, and `build` now has two days of slack. The project itself doesn't change. For more on previewing, see [Previewing changes](<https://docs.dhtmlx.com/planning-engine/net/live-projects/previewing-changes.md>).

### Analyzing without scheduling

Use [`Project.Analyze`](<https://docs.dhtmlx.com/planning-engine/net/api/project-analyze.md>) when you already have dates, for example from your own database or a gantt chart, and want the critical path for exactly those dates.

```csharp
using Plen;

var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");
var thursday = Moment.FromYmdHm(2026, 8, 13, 8, 0) ?? throw new InvalidOperationException("invalid date");

// "build" starts a day after "design" ends. A solve would pull it back to Wednesday.
var data = new ProjectData
{
    Tasks =
    [
        new TaskData("design") { StartDate = monday, Duration = 2.0 },
        new TaskData("build") { StartDate = thursday, Duration = 3.0 },
    ],
    Links = [new LinkData { Id = "l1", Source = "design", Target = "build" }],
};

var project = new Project();
var options = new AnalyzeOptions
{
    Analytics = new AnalyticsOptions { CriticalPath = true, Slack = true },
};
var result = project.Analyze(data, options);
Console.WriteLine(result.Updates.Count); // 0

var analytics = result.Analytics ?? throw new InvalidOperationException("analytics not requested");
if (analytics.CriticalPath is { } critical)
{
    foreach (var id in critical.Tasks)
        Console.WriteLine($"critical task: {id}");
}
foreach (var s in analytics.Slack ?? [])
    Console.WriteLine($"{s.Task}: total {s.Total} free {s.Free}");
```

Only `build` is critical. `design` has one day of total and free slack, because `build` starts a day later than the link requires. Link `l1` isn't critical: it isn't binding, and `design` isn't critical.

`Analyze` never changes the project. With a non-null `data` it validates and reads the data but doesn't install it. Invalid data throws [`InputException`](<https://docs.dhtmlx.com/planning-engine/net/api/core/errors/input-exception.md>), as described in [Error handling](<https://docs.dhtmlx.com/planning-engine/net/error-handling.md>). The result has no [`Updates`](<https://docs.dhtmlx.com/planning-engine/net/api/core/results/schedule-result.md#updates>) and no planner [`Conflicts`](<https://docs.dhtmlx.com/planning-engine/net/api/core/results/schedule-result.md#conflicts>), and its [`BaselineId`](<https://docs.dhtmlx.com/planning-engine/net/api/core/results/schedule-result.md#baselineid>) is `null`.

### Analyzing the project's current dates

Pass `null` to analyze the dates the project holds now, including edits that haven't been solved yet.

```csharp
using Plen;

var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");

var data = new ProjectData
{
    Tasks =
    [
        new TaskData("design") { StartDate = monday, Duration = 2.0 },
        new TaskData("build") { StartDate = monday, Duration = 3.0 },
        new TaskData("docs") { StartDate = monday, Duration = 1.0 },
    ],
    Links =
    [
        new LinkData { Id = "l1", Source = "design", Target = "build" },
        new LinkData { Id = "l2", Source = "design", Target = "docs" },
    ],
};

var project = new Project();
project.Solve(data, new SolveOptions());

var options = new AnalyzeOptions
{
    Analytics = new AnalyticsOptions { CriticalPath = true },
};

// Solved and clean: the result names the baseline it read.
var clean = project.Analyze(null, options);
Console.WriteLine(clean.BaselineId is not null); // True

// Commit an edit without solving.
var changes = new SchedulingChanges();
changes.Tasks.Update.Add(new TaskUpdate("docs") { Duration = 5.0 });
project.Apply(changes);

var dirty = project.Analyze(null, options);
Console.WriteLine(dirty.BaselineId is null); // True
if (dirty.Analytics?.CriticalPath is { } critical)
    Console.WriteLine($"critical: {string.Join(", ", critical.Tasks)}");
```

After the edit, the critical path is `design, docs`. [`Analyze`](<https://docs.dhtmlx.com/planning-engine/net/api/project-analyze.md>) doesn't change the project's solved status, so the project still needs [`Solve(null, …)`](<https://docs.dhtmlx.com/planning-engine/net/api/project-solve.md>) before [`Preview`](<https://docs.dhtmlx.com/planning-engine/net/api/project-preview.md>) works again. [`BaselineId`](<https://docs.dhtmlx.com/planning-engine/net/api/core/results/schedule-result.md#baselineid>) is set only when the project is solved and has no unsolved edits. Check it to tell whether the analytics describe the accepted baseline.

### Reading the result

Check [`Status`](<https://docs.dhtmlx.com/planning-engine/net/api/core/results/analytics.md#analyticsstatus>) first. Then read the lists you asked for. A flag you left off gives `null` for its list, even when the status is `Available`.

```csharp
using Plen;

var monday = Moment.FromYmdHm(2026, 8, 10, 8, 0) ?? throw new InvalidOperationException("invalid date");

var data = new ProjectData
{
    Tasks =
    [
        new TaskData("phase") { TaskType = TaskType.Summary },
        new TaskData("spec") { Parent = "phase", StartDate = monday, Duration = 1.0, Progress = 1.0 },
        new TaskData("review") { Parent = "phase", StartDate = monday, Duration = 2.0 },
        new TaskData("release") { StartDate = monday, Duration = 1.0 },
    ],
    Links = [new LinkData { Id = "l1", Source = "review", Target = "release" }],
};
data.Config.UseProgress = true;

var options = new SolveOptions
{
    Analytics = new AnalyticsOptions { CriticalPath = true, Slack = true },
};
var result = Engine.Schedule(data, options);

var analytics = result.Analytics ?? throw new InvalidOperationException("analytics not requested");
if (analytics.Status == AnalyticsStatus.Invalid)
{
    Console.WriteLine($"{result.Cycles.Count} dependency cycle(s), no analytics");
    return;
}
if (analytics.CriticalPath is { } critical)
    Console.WriteLine($"critical: {string.Join(", ", critical.Tasks)}");
foreach (var s in analytics.Slack ?? [])
    Console.WriteLine($"{s.Task}: total {s.Total} free {s.Free}");
```

The output shows each rule from the concept section:

```text
critical: review, phase, release
spec: total 0 free 0
review: total 0 free 0
release: total 0 free 0
```

- `phase` is critical because its child `review` is. It has no slack entry, since summaries never get one.
- `spec` is complete, so it reports zero slack. It still isn't on the critical path.
- The critical task list follows the scheduling graph order, not input order. Look tasks up by id instead of relying on their position.

If the links form a cycle, the solve returns unchanged dates and lists each cycle in [`result.Cycles`](<https://docs.dhtmlx.com/planning-engine/net/api/core/results/schedule-result.md#cycles>). The analytics then come back as `Invalid` with no lists. Fix the cycle and run again. For the rest of the result, see [Reading results](<https://docs.dhtmlx.com/planning-engine/net/scheduling/reading-results.md>).
