How na-sabbag/task-runner-sharp works
Project Type and Purpose
• TaskRunnerSharp is a .NET class-library (distributed via NuGet) whose sole purpose is to let client code register, run, monitor, and gather results from multiple synchronous or asynchronous tasks.
• It exposes a minimal public API (ITaskRunner) and a concrete implementation (TaskRunner) that manages tasks, thread‐safety, logging, and result aggregation.
File Structure
• Top-level:
• TaskRunnerSharp.sln – Visual Studio solution
• README.md, LICENSE, .gitignore
• src/
• ITaskRunner.cs – public interface defining Add(…), Run/RunAsync(), Results, Logs, Clear()
• TaskRunner.cs – core implementation of ITaskRunner
• TaskRunnerSharp.csproj – .NET class library project file
• tests/
• TaskRunnerSharp.Tests.csproj – test project
• TaskRunnerTests.cs – unit tests for core behaviors
• No web-UI or database subfolders – this is a pure in-process library.
README for Additional Insights
• Key features:
• Orchestrate both Task and Task<T>
• Synchronous and asynchronous execution
• Thread-safe operations
• Execution logging (lifecycle events for each task)
• Result aggregation for typed tasks
• Usage pattern: client creates a runner, calls Add(…), then Run()/RunAsync(), then inspects Results and Logs, then Clear().
a. Main Components to Show
1. Client Application – any .NET process that consumes the library
2. Public API Layer – ITaskRunner interface
3. Core Engine – TaskRunner class
• Task Registry / Queue
• Execution Engine (spawns and awaits System.Threading.Tasks)
• Result Aggregator
• Logging Component
• Thread‐Safety Mechanism (locks or concurrent collections)
4. Underlying .NET Task Infrastructure – System.Threading.Tasks.Task & Task<T>
5. Extension Points – custom implementations of ITaskRunner or middleware hooks (if any)
6. Test Harness – indicates how tests reference the public API and validate internal behavior
b. Relationships and Data Flow
• The Client invokes ITaskRunner.Add(…) → tasks land in the Task Registry.
• On Run()/RunAsync(), Core Engine picks tasks from the registry, hands them to the .NET Task infrastructure (Task.Run or direct invocation).
• As each Task completes, Execution Engine sends completion events to:
• Result Aggregator (for typed results)
• Logging Component (for lifecycle logs)
• Results and Logs are exposed back to the Client via IReadOnlyCollections.
• Clear() flushes the registry, results, and logs.
c. Architectural Patterns and Principles
• Interface‐driven design: ITaskRunner decouples client consumers from concrete implementation.
• Single Responsibility: separate modules for task orchestration, logging, and result aggregation.
• Thread safety via lock‐free or concurrent collections.
• Liskov Substitution: any ITaskRunner implementer can replace the default TaskRunner.
d. Relevant Technologies, Frameworks, Libraries
• C# 8+ / .NET Core or .NET Standard for maximum compatibility
• System.Threading.Tasks for parallelism
• Concurrent collections (e.g., ConcurrentQueue, ConcurrentBag)
• xUnit or MSTest for tests (per csproj)
• NuGet packaging for distribution
Detail
• Break the Core Engine into subcomponents to show responsibilities clearly.
• Thread‐safety boundaries (e.g., which collections are thread-safe).
• Both synchronous (Run) and asynchronous (RunAsync) flows if space permits.
• Don’t over-complicate: if a module isn’t in the codebase, leave it out.