A flexible and extensible task sequencing library for .NET that allows you to define, execute, and monitor ordered task pipelines. Supports asynchronous execution, cancellation tokens, error handling, and progress reporting for building robust workflows.
$ dotnet add package Shaunebu.Common.TaskSequenceManagerTaskSequenceManager is a lightweight, flexible, and cross-platform .NET library for managing sequences of asynchronous tasks with dependencies, priorities, phases, retries, and live dashboard reporting.
It works with .NET Core 3.1+ and .NET 8, without requiring MAUI, making it usable in Console, Web, or Desktop applications.
| Feature | Description |
|---|---|
| 🗂 Task Phases | Group tasks by logical phases, e.g., Initialization, Processing, Finalization. |
| ⚡ Priorities | Execute tasks based on priority when multiple tasks are ready. |
| 🔗 Dependencies | Tasks can depend on other tasks; they only run after dependencies complete successfully. |
| 🔄 Retries & Failures | Automatic retries on failure with configurable max retries and delays. |
| 📢 Events | Real-time events: TaskStarted, TaskCompleted, TaskFailed, ProgressChanged. |
| 📊 Live Dashboard | Console UI or custom listener to visualize live task status per phase & priority. |
| 📈 Progress Bar | Live percentage completion progress. |
| 📄 Serialization | Export tasks to JSON and load them back. |
| 🗂 Dependency Graph | Export dependency graph in DOT format for visualization. |
| 🎨 Color-coded output | Easy visualization of task state in console: ✅ success, ❌ failed, ⚠️ retry, ⏳ pending. |
Quick guide to integrate the library in a new project. For example:
Create a console or .NET app.
Add the NuGet package or project reference.
Instantiate TaskSequenceManager and define tasks.
Run tasks asynchronously with RunAsync.
Describe configurable properties of the manager:
MaxDegreeOfParallelism – control concurrency.
GlobalTimeout – set a maximum duration for the entire task sequence.
TaskItem.Timeout – set individual task timeouts.
TaskItem.MaxRetries – retries per task.
TaskItem.Priority – execution order when multiple tasks are ready.
TaskItem.Phase – logical grouping for reporting and dashboards.
Explain how failures are handled:
Tasks that throw exceptions can be retried automatically.
Failed tasks trigger the TaskFailed event.
Tasks depending on failed tasks won’t run until dependencies succeed.
Optional OnTaskRetry callback provides granular control per retry attempt.
Guide to create live dashboards:
Subscribe to TaskStarted, TaskCompleted, TaskFailed, ProgressChanged.
Console output or custom UI can reflect live progress.
Tasks can be grouped by Phase and sorted by Priority.
Export task progress as JSON for further reporting.
Explain task sequence serialization:
ToJson() – serialize current task states.
LoadFromJson() – reload task sequences for resuming.
DependencyGraphDot() – generate DOT graph for Graphviz visualization.
Tips for testing task sequences:
Create tasks with mock actions.
Simulate failures to test retries and recovery.
Validate correct execution order respecting dependencies and priorities.
Use console dashboards for debugging.
Dynamic task generation at runtime.
Parallel execution with controlled concurrency.
Conditional task execution based on previous task results.
Integration with logging frameworks (ILogger).
| Scenario | Description |
|---|---|
| 🔹 Setup Wizard | Execute sequential setup steps with dependencies. |
| 🔹 CI/CD Pipelines | Run build/test/deploy tasks in order with retries. |
| 🔹 Data Processing | Multi-step data import/transform/export pipelines. |
| 🔹 Automation Scripts | Background scripts or maintenance jobs with reporting. |
Install via NuGet:
dotnet add package Shaunebu.Common.TaskSequenceManager
using Shaunebu.Common.TaskSequenceManager;
using Shaunebu.Common.TaskSequenceManager.Models;
using System;
using System.Threading;
using System.Threading.Tasks;
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.WriteLine("🚀 TaskSequenceManager Dashboard Demo\n");
// Create the task manager
var taskManager = new TaskSequenceManager()
{
MaxDegreeOfParallelism = 2,
GlobalTimeout = TimeSpan.FromSeconds(30)
};
// Subscribe to events
taskManager.TaskStarted += t => DrawDashboard(taskManager.Tasks);
taskManager.TaskCompleted += t => DrawDashboard(taskManager.Tasks);
taskManager.TaskFailed += (t, ex) => DrawDashboard(taskManager.Tasks);
taskManager.ProgressChanged += p => DrawProgressBar(p);
// Progress bar
void DrawProgressBar(double progress)
{
const int barWidth = 40;
int filled = (int)(progress / 100 * barWidth);
Console.CursorVisible = false;
Console.Write("[");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write(new string('█', filled));
Console.ResetColor();
Console.Write(new string('-', barWidth - filled));
Console.Write($"] {progress:0.##}%\r");
if (progress >= 100) Console.WriteLine();
}
// Dashboard display
void DrawDashboard(IReadOnlyList<TaskItem> tasks)
{
Console.Clear();
Console.WriteLine("=== Task Dashboard ===\n");
foreach (var t in tasks.OrderBy(t => t.Phase).ThenByDescending(t => t.Priority))
{
var status = t.IsCompleted
? t.IsSuccessful ? "✅ Success" : "❌ Failed"
: "⏳ Running / Pending";
Console.WriteLine($"[{t.Phase ?? "General"} | Priority {t.Priority}] {t.Name} - {status}");
}
Console.WriteLine("\n=====================");
}
// Add tasks
taskManager.AddTask(async token =>
{
await Task.Delay(1000, token);
Console.WriteLine("Task A executed!");
}, name: "Task A", phase: "Initialization", priority: 2);
var taskB = taskManager.AddTask(async token =>
{
await Task.Delay(1500, token);
Console.WriteLine("Task B executed!");
}, name: "Task B", phase: "Processing", priority: 1, dependencies: new[] { "Task A" });
var taskC = taskManager.AddTask(async token =>
{
await Task.Delay(500, token);
Console.WriteLine("Task C executed!");
throw new InvalidOperationException("Simulated failure");
}, name: "Task C", phase: "Processing", priority: 2, maxRetries: 2, dependencies: new[] { "Task A" });
// Retry event
taskC.OnTaskRetry = (t, attempt, ex) =>
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"⚠️ {t.Name} retry {attempt} due to: {ex.Message}");
Console.ResetColor();
};
taskManager.AddTask(async token =>
{
await Task.Delay(700, token);
Console.WriteLine("Task D executed!");
}, name: "Task D", phase: "Finalization", priority: 1, dependencies: new[] { "Task B", "Task C" });
// Run all tasks
using var cts = new CancellationTokenSource();
await taskManager.RunAsync(cts.Token);
// Final dashboard
DrawDashboard(taskManager.Tasks);
// Export tasks JSON
var json = taskManager.ToJson();
Console.WriteLine("\n📄 Task sequence JSON:");
Console.WriteLine(json);
// Export dependency graph
var dotGraph = taskManager.DependencyGraphDot();
Console.WriteLine("\n🗂 Dependency Graph DOT:");
Console.WriteLine(dotGraph);
Designed for cross-platform use without MAUI dependencies.
Supports parallel execution via MaxDegreeOfParallelism.
Handles task failures, timeouts, and automatic retries.
Use Phases and Priorities for building dashboards and reporting.