Class QueueTaskScheduler
A task scheduler that queues tasks and executes them in a controlled manner. Limits the number of concurrent tasks and provides mechanisms for waiting for all tasks to complete.
public class QueueTaskScheduler : TaskScheduler, IDisposable
- Inheritance
-
QueueTaskScheduler
- Implements
- Inherited Members
- Extension Methods
Constructors
QueueTaskScheduler(int, int)
Initializes a new instance of the QueueTaskScheduler class.
public QueueTaskScheduler(int maxIdlingTaskNum, int maxWorkingTaskNum = 0)
Parameters
maxIdlingTaskNum
intThe maximum number of tasks that can be queued.
maxWorkingTaskNum
intThe maximum number of tasks that can be executed concurrently. If 0, defaults to the number of processors.
Properties
CancellationToken
Gets the cancellation token used to cancel the working task.
public CancellationToken CancellationToken { get; }
Property Value
IdlingTaskNum
Gets the number of tasks currently waiting in the queue.
public int IdlingTaskNum { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposing
bool
GetScheduledTasks()
Gets the tasks currently scheduled for execution.
protected override IEnumerable<Task> GetScheduledTasks()
Returns
- IEnumerable<Task>
An enumerable of the tasks currently scheduled.
QueueTask(Task)
Queues a task to the scheduler.
protected override void QueueTask(Task task)
Parameters
task
TaskThe task to be queued.
Test()
Tests the QueueTaskScheduler by running multiple tasks concurrently.
public static void Test()
TryExecuteTaskInline(Task, bool)
Tries to execute a task synchronously on the current thread.
protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
Parameters
task
TaskThe task to be executed.
taskWasPreviouslyQueued
boolWhether the task was previously queued to the scheduler.
Returns
- bool
true if the task was successfully executed; otherwise, false.
WaitAll()
Waits for all queued tasks to complete.
public void WaitAll()