ScheduleTaskHelper.Tasks 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package ScheduleTaskHelper.Tasks --version 1.0.2
                    
NuGet\Install-Package ScheduleTaskHelper.Tasks -Version 1.0.2
                    
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="ScheduleTaskHelper.Tasks" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ScheduleTaskHelper.Tasks" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="ScheduleTaskHelper.Tasks" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ScheduleTaskHelper.Tasks --version 1.0.2
                    
#r "nuget: ScheduleTaskHelper.Tasks, 1.0.2"
                    
#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.
#:package ScheduleTaskHelper.Tasks@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ScheduleTaskHelper.Tasks&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=ScheduleTaskHelper.Tasks&version=1.0.2
                    
Install as a Cake Tool

ScheduleTaskHelper.Tasks

?? Overview

ScheduleTaskHelper.Tasks is a task scheduling framework designed for .NET applications. It provides support for various scheduling modes, including periodic tasks and Cron-based scheduling. The framework is highly extensible and integrates seamlessly with plugin architectures, making it ideal for applications requiring efficient task management.

??? Key Features

  • Periodic and Cron Scheduling: Supports both fixed-interval and Cron-based task scheduling.
  • Task Prioritization: Manage task execution order within groups.
  • Retry Mechanism: Automatically retries failed tasks with configurable retry policies.
  • Extensibility: Easily integrates with plugin-based architectures.
  • Task Execution Tracking: Monitor task execution status and history.
  • Distributed Locking: Ensures safe execution in multi-node environments.

??? Architecture

Core Components

1. Scheduled Task Interface (IScheduledTask)

Defines the contract for all scheduled tasks, including properties for task name, group, priority, and execution intervals.

public interface IScheduledTask
{
    string Name { get; }
    string Group { get; }
    TimeSpan InitialDelay { get; }
    TimeSpan Period { get; }
    int Priority { get; }

    Task<int> Execute();
    void Stop();
}
2. Cron Scheduled Task Interface (ICronScheduledTask)

Extends IScheduledTask to support Cron-based scheduling.

public interface ICronScheduledTask : IScheduledTask
{
    bool Immediate { get; }
    string CronExpression { get; }
    DateTime GetNextExecution(DateTime now);
}
3. Base Task (BaseTask)

Provides a default implementation of IScheduledTask, simplifying task development.

4. Base Cron Task (BaseCronTask)

Extends BaseTask to support Cron-based scheduling.

5. Task Retry Queue (TaskRetryQueue)

Manages failed tasks and retries them based on configurable policies.

6. Scheduled Thread Pool (ScheduledThreadPool)

Manages task execution, including scheduling, prioritization, and concurrency control.

?? Configuration

Task Configuration File (pluginconfig.json)

Defines task-specific settings, including scheduling intervals, priorities, and parameters.

{
  "TaskConfigurations": {
    "SampleTask": {
      "Enabled": true,
      "Group": "SampleTasks",
      "Priority": 1,
      "InitialDelay": "00:00:10",
      "Period": "00:05:00"
    },
    "SampleCronTask": {
      "Enabled": true,
      "Group": "SampleTasks",
      "CronExpression": "0 */5 * * * *",
      "ExecuteImmediately": true
    }
  }
}

Key Configuration Fields

  • Enabled: Whether the task is enabled.
  • Group: The group to which the task belongs.
  • Priority: Execution priority within the group.
  • InitialDelay: Delay before the first execution.
  • Period: Interval between executions for periodic tasks.
  • CronExpression: Cron expression for scheduling.
  • ExecuteImmediately: Whether to execute the task immediately upon startup.

?? Getting Started

1. Create a Task

Implement the IScheduledTask or ICronScheduledTask interface to create a new task.

public class SampleTask : BaseTask
{
    public SampleTask(string name, string group, TimeSpan initDelay, TimeSpan period, int priority)
        : base(name, group, initDelay, period, priority)
    {
    }

    public override Task<int> Execute()
    {
        Console.WriteLine($"Executing task: {Name}");
        return Task.FromResult(0);
    }
}

2. Schedule Tasks

Use the ScheduledThreadPool to schedule tasks dynamically.

var threadPool = new ScheduledThreadPool();
var task = new SampleTask("Task1", "Group1", TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(5), 1);
threadPool.Schedule(task, task.InitialDelay, task.Period, task.Priority);

3. Use Cron Tasks

Create tasks using the BaseCronTask class for Cron-based scheduling.

public class SampleCronTask : BaseCronTask
{
    public SampleCronTask(string name, string cronExpression)
        : base(name, cronExpression, 1, "CronGroup", true)
    {
    }

    public override Task<int> Execute()
    {
        Console.WriteLine($"Executing Cron task: {Name}");
        return Task.FromResult(0);
    }
}

?? API Documentation

Scheduled Thread Pool (ScheduledThreadPool)

  • Schedule: Schedules a periodic task.
  • ScheduleCron: Schedules a Cron-based task.
  • Shutdown: Stops all scheduled tasks.

Task Retry Queue (TaskRetryQueue)

  • AddForRetry: Adds a failed task to the retry queue.
  • CheckRetryQueue: Processes tasks in the retry queue.

?? License

This project is licensed under the MIT License. See the LICENSE file for details.

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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ScheduleTaskHelper.Tasks:

Package Downloads
ScheduleTaskHelper.Plugins

ScheduleTaskHelper.Plugins 是一個專為 .NET 應用程式設計的插件式架構框架,提供動態載入與管理外部插件的能力。此框架支援插件的初始化、服務註冊、任務管理與卸載,並透過標準化的介面與基底類別,簡化插件的開發與整合。適用於需要高擴展性與模組化設計的應用場景。

ScheduleTaskHelper.Core

ScheduleTaskHelper 是一個功能強大的任務排程與執行框架,專為 .NET 應用程式設計。它支援多種任務排程模式(包括定時與 Cron 表達式),並整合了分散式鎖機制、任務重試佇列與事件驅動架構,確保任務執行的可靠性與高效性。此外,該框架支援插件式架構,允許動態載入外部插件,適合用於分散式系統或需要高效任務管理的應用場景。

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.7 10 8/20/2025
1.0.6 8 8/20/2025
1.0.5 13 8/20/2025
1.0.4 10 8/20/2025
1.0.3 9 8/20/2025
1.0.2 11 8/20/2025
1.0.1 11 8/20/2025
1.0.0 15 8/20/2025