SchedulerTask 1.1.3
dotnet add package SchedulerTask --version 1.1.3
NuGet\Install-Package SchedulerTask -Version 1.1.3
<PackageReference Include="SchedulerTask" Version="1.1.3" />
paket add SchedulerTask --version 1.1.3
#r "nuget: SchedulerTask, 1.1.3"
// 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 viaAddTask
. Includes aWait()
method.AddTaskImmediately(Func<Task> task)
Executes a task with the highest priority.Wait()
Waits for all delayed tasks added viaAddTaskWait
to complete.WaitAll()
Waits for all tasks added viaAddTask
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
- Clone the repository:
git clone https://github.com/yourusername/task-scheduler-library.git
- Include the project in your solution.
- Add namespaces
TaskScheduler.Contracts
andTaskScheduler.Service
in your code.
Requirements
- .NET 8.0
- Windows (64-bit)
📜 Usage Examples
- 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();
- Executing tasks immediately:
var scheduler = new TaskHardExternal();
await scheduler.AddTaskImmediately(async () =>
{
// Long-running CPU-bound task
await Task.Delay(1000);
Console.WriteLine("Task completed");
});
- 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();
- 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 | Versions 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. |
-
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.