A lightweight, flexible task scheduler for .NET applications designed to schedule tasks dynamically with an easy-to-use API. This scheduler supports one-time and recurring tasks using a simple interface for task execution.
- Schedule tasks dynamically at runtime.
- Support for both one-time and recurring tasks.
- Customizable task execution intervals.
- Simple interface to implement custom task handling logic.
- Thread-safe task addition and removal.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- .NET Framework or .NET Core installed on your machine.
To use the Task Scheduler in your project, follow these steps:
- Clone the repository or download the source code.
- Include the
Scheduler
namespace in your project. - Implement the
ITaskHandler
interface to define how tasks should be executed.
Here is a basic example of how to use the Task Scheduler:
- Implement the
ITaskHandler
interface:
using Scheduler;
public class MyTaskHandler : ITaskHandler
{
public void DoTask(Task task)
{
// Task execution logic goes here.
}
}
var scheduler = new TaskScheduler();
var myTask = new Task();
var myTaskHandler = new MyTaskHandler();
// Schedule the task for execution every 10 seconds, looping indefinitely.
scheduler.AddScheduledTask(myTask, 10, true, myTaskHandler);
// Start the task scheduler.
scheduler.StartService();
TaskScheduler: The main class responsible for managing and executing scheduled tasks. ITaskHandler: Interface that needs to be implemented to handle the execution of tasks. Task: Represents a task with an ID, parameters, and active state. ScheduledTask: Represents a scheduled task with execution details.
Please feel free to contribute.
This project is licensed under the MIT License