From 6d0828ef97996792ade7830f17fb322b4b7b853b Mon Sep 17 00:00:00 2001
From: Volodymyr Dombrovskyi <5788605+dombrovsky@users.noreply.github.com>
Date: Sat, 2 Aug 2025 14:02:20 -0600
Subject: [PATCH 1/3] Add sourcedoc to core types
---
...kFlowServiceCollectionExtensionsFixture.cs | 2 +-
...kFlowServiceCollectionExtensionsFixture.cs | 2 +-
TaskFlow/CurrentThreadTaskFlow.cs | 78 ++++++++
TaskFlow/DedicatedThreadTaskFlow.cs | 68 +++++++
TaskFlow/ITaskFlow.cs | 38 ++++
TaskFlow/ITaskFlowInfo.cs | 22 +++
TaskFlow/ITaskScheduler.cs | 46 +++++
TaskFlow/TaskFlow.cs | 104 ++++++++++
TaskFlow/TaskFlowBase.cs | 182 ++++++++++++++++++
TaskFlow/TaskFlowOptions.cs | 74 ++++++-
TaskFlow/TaskFlowSynchronizationContext.cs | 87 +++++++++
TaskFlow/ThreadTaskFlow.cs | 134 +++++++++++++
12 files changed, 833 insertions(+), 4 deletions(-)
diff --git a/TaskFlow.Extensions.Microsoft.DependencyInjection.Tests/CustomTaskFlowServiceCollectionExtensionsFixture.cs b/TaskFlow.Extensions.Microsoft.DependencyInjection.Tests/CustomTaskFlowServiceCollectionExtensionsFixture.cs
index 7bcc59a..44f4c74 100644
--- a/TaskFlow.Extensions.Microsoft.DependencyInjection.Tests/CustomTaskFlowServiceCollectionExtensionsFixture.cs
+++ b/TaskFlow.Extensions.Microsoft.DependencyInjection.Tests/CustomTaskFlowServiceCollectionExtensionsFixture.cs
@@ -6,7 +6,7 @@ namespace TaskFlow.Extensions.Microsoft.DependencyInjection.Tests
using System.Threading.Tasks.Flow;
[TestFixture]
- public sealed class CustomTaskFlowServiceCollectionExtensionsFixture
+ internal sealed class CustomTaskFlowServiceCollectionExtensionsFixture
{
[Test]
public void AddTaskFlow_ShouldRegisterTaskFlowInfoAndTaskScheduler()
diff --git a/TaskFlow.Extensions.Microsoft.DependencyInjection.Tests/DefaultTaskFlowServiceCollectionExtensionsFixture.cs b/TaskFlow.Extensions.Microsoft.DependencyInjection.Tests/DefaultTaskFlowServiceCollectionExtensionsFixture.cs
index bff277e..a06206f 100644
--- a/TaskFlow.Extensions.Microsoft.DependencyInjection.Tests/DefaultTaskFlowServiceCollectionExtensionsFixture.cs
+++ b/TaskFlow.Extensions.Microsoft.DependencyInjection.Tests/DefaultTaskFlowServiceCollectionExtensionsFixture.cs
@@ -5,7 +5,7 @@ namespace TaskFlow.Extensions.Microsoft.DependencyInjection.Tests
using System.Threading.Tasks.Flow;
[TestFixture]
- public sealed class DefaultTaskFlowServiceCollectionExtensionsFixture
+ internal sealed class DefaultTaskFlowServiceCollectionExtensionsFixture
{
[Test]
public void AddTaskFlow_ShouldRegisterTaskFlowInfoAndTaskScheduler()
diff --git a/TaskFlow/CurrentThreadTaskFlow.cs b/TaskFlow/CurrentThreadTaskFlow.cs
index 56f2079..3b6084e 100644
--- a/TaskFlow/CurrentThreadTaskFlow.cs
+++ b/TaskFlow/CurrentThreadTaskFlow.cs
@@ -1,21 +1,99 @@
namespace System.Threading.Tasks.Flow
{
+ ///
+ /// A task flow implementation that executes tasks on the thread that calls the method.
+ ///
+ ///
+ ///
+ /// The class provides a task scheduling mechanism that
+ /// executes tasks on a specific thread provided by the caller. Unlike ,
+ /// which creates its own thread, this class allows you to use an existing thread for task execution.
+ ///
+ ///
+ /// This implementation is useful when you want to execute tasks on a specific thread, such as:
+ ///
+ ///
+ /// A UI thread in a desktop application
+ /// A worker thread that you manage externally
+ /// A thread with specific properties or priority settings
+ ///
+ ///
+ /// Note that the method must be called to start the task flow, and it
+ /// will block the calling thread until the task flow is disposed.
+ ///
+ ///
+ /// Basic usage with a background thread:
+ ///
+ /// var taskFlow = new CurrentThreadTaskFlow();
+ ///
+ /// // Start the task flow on a background thread
+ /// var thread = new Thread(() => taskFlow.Run()) { IsBackground = true };
+ /// thread.Start();
+ ///
+ /// // Enqueue tasks for execution on the background thread
+ /// var task1 = taskFlow.Enqueue(() => Console.WriteLine("Task 1"));
+ /// var task2 = taskFlow.Enqueue(() => Console.WriteLine("Task 2"));
+ ///
+ /// // Wait for tasks to complete and dispose the task flow
+ /// await Task.WhenAll(task1, task2);
+ /// await taskFlow.DisposeAsync();
+ ///
+ ///
+ ///
public sealed class CurrentThreadTaskFlow : ThreadTaskFlow
{
private int _managedThreadId;
+ ///
+ /// Initializes a new instance of the class with default options.
+ ///
+ ///
+ /// This constructor uses the default options from .
+ /// The task flow will not start processing tasks until the method is called.
+ ///
public CurrentThreadTaskFlow()
: this(TaskFlowOptions.Default)
{
}
+ ///
+ /// Initializes a new instance of the class with the specified options.
+ ///
+ /// The options that configure the behavior of this task flow.
+ /// Thrown when is null.
+ ///
+ /// The task flow will not start processing tasks until the method is called.
+ ///
public CurrentThreadTaskFlow(TaskFlowOptions options)
: base(options)
{
}
+ ///
+ /// Gets the managed thread ID of the thread that is executing tasks in this task flow.
+ ///
+ ///
+ /// This property returns the thread ID of the thread that called the method.
+ /// If the method has not been called yet, the thread ID is not defined.
+ ///
public override int ThreadId => _managedThreadId;
+ ///
+ /// Starts the task flow execution on the current thread and blocks until the task flow is disposed.
+ ///
+ ///
+ ///
+ /// This method must be called to start the task flow and begin processing tasks.
+ /// It will block the calling thread until the task flow is disposed.
+ ///
+ ///
+ /// Tasks enqueued before calling this method will be processed once it is called.
+ /// Tasks enqueued after calling this method will be processed as they are received.
+ ///
+ ///
+ /// To stop the execution, dispose the task flow from another thread or by using a cancellation token.
+ ///
+ ///
public void Run()
{
Starting();
diff --git a/TaskFlow/DedicatedThreadTaskFlow.cs b/TaskFlow/DedicatedThreadTaskFlow.cs
index 1cff49a..8ab1805 100644
--- a/TaskFlow/DedicatedThreadTaskFlow.cs
+++ b/TaskFlow/DedicatedThreadTaskFlow.cs
@@ -1,14 +1,76 @@
namespace System.Threading.Tasks.Flow
{
+ ///
+ /// A task flow implementation that executes tasks on a dedicated background thread.
+ ///
+ ///
+ ///
+ /// The class provides a task scheduling mechanism that
+ /// executes tasks on a dedicated background thread created specifically for this task flow.
+ /// The thread is automatically started during construction and continues running until the task flow is disposed.
+ ///
+ ///
+ /// This implementation is useful when you want to:
+ ///
+ ///
+ /// Execute tasks in a background thread that doesn't block the main application thread
+ /// Process tasks sequentially in a dedicated thread
+ /// Isolate task execution from other parts of the application
+ ///
+ ///
+ /// The dedicated thread is created as a background thread, which means it will not prevent
+ /// the application from exiting if all foreground threads have terminated.
+ ///
+ ///
+ /// Basic usage:
+ ///
+ /// // Create a task flow with a dedicated thread named "MyBackgroundThread"
+ /// using var taskFlow = new DedicatedThreadTaskFlow("MyBackgroundThread");
+ ///
+ /// // Enqueue tasks for execution on the dedicated thread
+ /// var task1 = taskFlow.Enqueue(() => Console.WriteLine("Task 1"));
+ /// var task2 = taskFlow.Enqueue(() => Console.WriteLine("Task 2"));
+ ///
+ /// // Wait for tasks to complete
+ /// await Task.WhenAll(task1, task2);
+ ///
+ ///
+ ///
public sealed class DedicatedThreadTaskFlow : ThreadTaskFlow
{
private readonly Thread _thread;
+ ///
+ /// Initializes a new instance of the class with default options and an optional name.
+ ///
+ /// Optional name for the dedicated thread. If null or empty, uses the class name.
+ ///
+ ///
+ /// This constructor uses the default options from .
+ ///
+ ///
+ /// The task flow immediately creates and starts a dedicated background thread for processing tasks.
+ ///
+ ///
public DedicatedThreadTaskFlow(string? name = default)
: this(TaskFlowOptions.Default, name)
{
}
+ ///
+ /// Initializes a new instance of the class with the specified options and an optional name.
+ ///
+ /// The options that configure the behavior of this task flow.
+ /// Optional name for the dedicated thread. If null or empty, uses the class name.
+ /// Thrown when is null.
+ ///
+ ///
+ /// The task flow immediately creates and starts a dedicated background thread for processing tasks.
+ ///
+ ///
+ /// The thread name is useful for debugging and thread identification in thread dumps or profiling tools.
+ ///
+ ///
public DedicatedThreadTaskFlow(TaskFlowOptions options, string? name = default)
: base(options)
{
@@ -22,6 +84,12 @@ public DedicatedThreadTaskFlow(TaskFlowOptions options, string? name = default)
_thread.Start(null);
}
+ ///
+ /// Gets the managed thread ID of the dedicated thread that is executing tasks in this task flow.
+ ///
+ ///
+ /// This property returns the thread ID of the dedicated thread created for this task flow.
+ ///
public override int ThreadId => _thread.ManagedThreadId;
}
}
\ No newline at end of file
diff --git a/TaskFlow/ITaskFlow.cs b/TaskFlow/ITaskFlow.cs
index 9fcbd63..bf98284 100644
--- a/TaskFlow/ITaskFlow.cs
+++ b/TaskFlow/ITaskFlow.cs
@@ -1,7 +1,45 @@
namespace System.Threading.Tasks.Flow
{
+ ///
+ /// Defines a unified interface for task flow execution that combines scheduling, information, and disposal capabilities.
+ ///
+ ///
+ ///
+ /// The interface combines multiple interfaces to provide a complete API for task management:
+ ///
+ ///
+ /// - For enqueueing tasks for execution
+ /// - For accessing information about the task flow
+ /// - For asynchronous cleanup of resources
+ /// - For synchronous cleanup of resources
+ ///
+ ///
+ /// Implementations of this interface are responsible for:
+ ///
+ ///
+ /// Managing the execution of tasks in a controlled manner
+ /// Ensuring proper task cancellation during disposal
+ /// Providing configuration options through the property
+ /// Supporting both synchronous and asynchronous disposal patterns
+ ///
+ ///
public interface ITaskFlow : ITaskScheduler, ITaskFlowInfo, IAsyncDisposable, IDisposable
{
+ ///
+ /// Synchronously disposes the task flow with a specified timeout.
+ ///
+ /// The maximum time to wait for task completion.
+ /// true if all tasks completed within the specified timeout; otherwise, false.
+ ///
+ ///
+ /// This method attempts to dispose of the task flow asynchronously but with a time limit.
+ /// If the specified timeout is reached before all tasks complete, the method returns false,
+ /// but resources are still properly disposed.
+ ///
+ ///
+ /// If tasks don't respond to cancellation, they may continue running after this method returns.
+ ///
+ ///
bool Dispose(TimeSpan timeout);
}
}
\ No newline at end of file
diff --git a/TaskFlow/ITaskFlowInfo.cs b/TaskFlow/ITaskFlowInfo.cs
index 6fe0975..b284d64 100644
--- a/TaskFlow/ITaskFlowInfo.cs
+++ b/TaskFlow/ITaskFlowInfo.cs
@@ -1,7 +1,29 @@
namespace System.Threading.Tasks.Flow
{
+ ///
+ /// Defines a contract for accessing information about a task flow's configuration.
+ ///
+ ///
+ ///
+ /// The interface provides a way to access configuration
+ /// information about a task flow without exposing the ability to schedule tasks or
+ /// manage the task flow's lifecycle.
+ ///
+ ///
+ /// This interface is useful for components that need to read task flow configuration
+ /// but should not have the ability to enqueue tasks or dispose the task flow.
+ ///
+ ///
public interface ITaskFlowInfo
{
+ ///
+ /// Gets the options that configure the behavior of the task flow.
+ ///
+ ///
+ /// The options object contains configuration settings that affect the behavior
+ /// of the task flow, such as the task scheduler to use and timeout settings
+ /// for synchronous disposal operations.
+ ///
TaskFlowOptions Options { get; }
}
}
\ No newline at end of file
diff --git a/TaskFlow/ITaskScheduler.cs b/TaskFlow/ITaskScheduler.cs
index 554c093..5df81c6 100644
--- a/TaskFlow/ITaskScheduler.cs
+++ b/TaskFlow/ITaskScheduler.cs
@@ -1,7 +1,53 @@
namespace System.Threading.Tasks.Flow
{
+ ///
+ /// Defines a contract for scheduling tasks for execution in a controlled manner.
+ ///
+ ///
+ ///
+ /// The interface provides a standardized way to enqueue tasks
+ /// for execution according to the implementation's scheduling strategy.
+ ///
+ ///
+ /// Implementations may enforce different execution patterns such as:
+ ///
+ ///
+ /// Sequential execution (one task at a time)
+ /// Parallel execution with controlled concurrency
+ /// Priority-based scheduling
+ /// Custom execution strategies
+ ///
+ ///
public interface ITaskScheduler
{
+ ///
+ /// Enqueues a task function for execution according to the scheduler's strategy.
+ ///
+ /// The type of result produced by the task.
+ /// The function to execute that returns a .
+ /// An optional state object that is passed to the .
+ /// A cancellation token that can be used to cancel the operation.
+ /// A representing the result of the enqueued task.
+ ///
+ ///
+ /// The execution behavior of this method depends on the specific implementation of the scheduler.
+ /// Tasks may be executed immediately, queued for sequential execution, or handled according to
+ /// other scheduling strategies.
+ ///
+ ///
+ /// The returned task completes when the enqueued function completes, and will propagate any
+ /// exceptions thrown by the function.
+ ///
+ ///
+ /// Implementations should ensure that:
+ ///
+ ///
+ /// The provided cancellation token is honored
+ /// Exceptions from the task function are propagated to the returned task
+ /// Resources are properly managed when the scheduler is disposed
+ ///
+ ///
+ /// Thrown if the scheduler has been disposed.
Task Enqueue(Func