SchedulerTask 1.1.3

dotnet add package SchedulerTask --version 1.1.3                
NuGet\Install-Package SchedulerTask -Version 1.1.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SchedulerTask" Version="1.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SchedulerTask --version 1.1.3                
#r "nuget: SchedulerTask, 1.1.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SchedulerTask as a Cake Addin
#addin nuget:?package=SchedulerTask&version=1.1.3

// Install SchedulerTask as a Cake Tool
#tool nuget:?package=SchedulerTask&version=1.1.3                

Task Scheduler Library

Task Scheduler Library is a library for managing tasks with varying throughput. It provides an interface and three implementation classes for handling different types of tasks: heavy (CPU-bound), tasks within CPU-bound, and input-output operations (I/O-bound).

📖 Table of Contents


🛠️ Features

  • Scalability: Ability to configure the number of concurrent tasks.
  • Flexibility: Supports both CPU-bound and I/O-bound tasks.
  • Safety: Manages tasks using semaphores to prevent conflicts.
  • Convenience: Methods for adding tasks, waiting for completion, and monitoring active tasks.

🔗 IScheduler Interface

The IScheduler interface defines basic methods for working with tasks:

  • AddTask(Func<Task> task)
    Adds a task to the scheduler.

  • AddTaskWait(Func<Task> task)
    Adds a task to a separate queue of grouped tasks executed independently from tasks added via AddTask. Includes a Wait() method.

  • AddTaskImmediately(Func<Task> task)
    Executes a task with the highest priority.

  • Wait()
    Waits for all delayed tasks added via AddTaskWait to complete.

  • WaitAll()
    Waits for all tasks added via AddTask to complete.

  • GetCurrentCount()
    Returns the current number of running tasks.

  • ChangeMaxConcurrency(int maxConcurrency)
    Changes the maximum number of concurrently running tasks.


⚙️ Implementations

The library includes three IScheduler implementations, each with different throughput settings:

TaskHardExternal

  • Scheduler for heavy (CPU-bound) or long-waiting tasks.
  • Throughput = number of CPU cores.
  • Used to limit the execution of long-running tasks.

TaskHardInternal

  • Scheduler for internal tasks executed within TaskHardExternal.
  • Throughput = number of CPU cores × 2.
  • Ideal for managing tasks with higher contention.

TaskSimple

  • Scheduler for input-output (I/O-bound) operations.
  • Throughput = number of CPU cores × 15.
  • Used for operations that do not require intensive computations.

📦 Installation

  1. Clone the repository:
    git clone https://github.com/yourusername/task-scheduler-library.git
    
  2. Include the project in your solution.
  3. Add namespaces TaskScheduler.Contracts and TaskScheduler.Service in your code.

Requirements

  • .NET 8.0
  • Windows (64-bit)

📜 Usage Examples

  1. Adding a task to the task list:
var scheduler = new TaskHardExternal();
await scheduler.AddTask(async () =>
{
    // Long-running CPU-bound task
    await Task.Delay(1000);
    Console.WriteLine("Task completed");
});
// If you need to wait for all tasks to complete
await scheduler.WaitAll();
  1. Executing tasks immediately:
var scheduler = new TaskHardExternal();
await scheduler.AddTaskImmediately(async () =>
{
    // Long-running CPU-bound task
    await Task.Delay(1000);
    Console.WriteLine("Task completed");
});
  1. Adding an I/O-bound task to the task list:
var scheduler = new TaskSimple();
await scheduler.AddTaskImmediately(async () =>
{
    // Simple I/O-bound task
    await Task.Delay(200);
    Console.WriteLine("Task completed");
});
// If you need to wait for all tasks to complete
await scheduler.WaitAll();
  1. Adding tasks to a separate list of tasks that can be executed in parallel with the main tasks:
var scheduler = new TaskHardExternal();
await scheduler.AddTaskWait(async () =>
{
    // Long-running CPU-bound task
    await Task.Delay(1000);
    Console.WriteLine("Task completed");
});
await scheduler.AddTaskWait(async () =>
{
    // Long-running CPU-bound task
    await Task.Delay(1000);
    Console.WriteLine("Task completed");
});
// Wait for all tasks to complete
await scheduler.Wait();
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.3 55 1/19/2025
1.1.2 48 1/19/2025
1.1.1 48 1/19/2025
1.1.0 48 1/19/2025
1.0.3 47 1/19/2025
1.0.2 42 1/19/2025
1.0.1 50 1/18/2025