A lightweight, high-performance .NET library for scheduling timed events with configurable warning systems. Perfect for game development, simulation environments, and any application requiring precise event timing and lifecycle management.
- โฐ Precise Event Scheduling: Chronological event ordering with efficient O(n) insertion
โ ๏ธ Warning System: Configurable advance warnings before event execution- ๐ Event Lifecycle Management: Schedule, reschedule, cancel, and track events
- ๐๏ธ Generic Architecture: Works with any
IWorldDateTimeProviderimplementation - ๐ฆ Builder Pattern: Fluent API for declarative event construction
- ๐ Event Querying: Retrieve events by ID or enumerate all scheduled events
- ๐ Observer Pattern: Event execution notifications and callbacks
- โ 98.5% Test Coverage: Comprehensive unit and integration tests
dotnet add package SimpleEventSchedulergit clone https://github.com/hickagpt/EventScheduler.git
cd eventscheduler
dotnet build EventScheduler.slnusing EventScheduler;
using EventScheduler.Abstractions;
// 1. Create a time provider (implement your own or use a mock)
public class GameTimeProvider : IWorldDateTimeProvider
{
public DateTime CurrentTime { get; set; } = DateTime.Now;
}
// 2. Create an event scheduler
var scheduler = new EventScheduler<GameTimeProvider>();
var gameWorld = new GameTimeProvider();
// 3. Schedule a simple event
var futureTime = gameWorld.CurrentTime.AddSeconds(30);
var eventId = scheduler.ScheduleEvent(
new ScheduledEvent<GameTimeProvider>.Builder()
.SetScheduledTime(futureTime)
.SetName("Player Spawn")
.SetRunAction(world => Console.WriteLine("Player spawned!"))
.Build()
);
Console.WriteLine($"Scheduled event with ID: {eventId}");// Create an event with a 1-minute warning
var missionTime = gameWorld.CurrentTime.AddMinutes(5);
var missionEvent = new ScheduledEvent<GameTimeProvider>.Builder()
.SetScheduledTime(missionTime)
.SetName("Mission Start")
.SetDescription("Assault the enemy base")
.SetWarningBefore(TimeSpan.FromMinutes(1)) // Warn 1 minute before
.SetRunAction(world => StartMission(world))
.SetRunWarningAction(world => ShowMissionWarning(world))
.Build();
// Schedule the event
scheduler.ScheduleEvent(missionEvent);
// Subscribe to execution notifications
scheduler.ScheduledEventRun += (sender, args) =>
{
Console.WriteLine($"Event completed: {args.ScheduledEvent.Name}");
};
// Update the scheduler (call this regularly, e.g., in your game loop)
scheduler.Update(gameWorld);// Custom time provider for accelerated time scenarios
public class AcceleratedGameTime : IWorldDateTimeProvider
{
private DateTime _startTime = DateTime.Now;
public double TimeMultiplier { get; set; } = 1.0;
public DateTime CurrentTime =>
_startTime.AddSeconds((DateTime.Now - _startTime).TotalSeconds * TimeMultiplier);
}
// Use in fast-forward scenarios (e.g., time-lapse gameplay)
var acceleratedTime = new AcceleratedGameTime { TimeMultiplier = 10.0 };
var scheduler = new EventScheduler<AcceleratedGameTime>();public interface IEventScheduler<TWorld> where TWorld : IWorldDateTimeProvider
{
// Events
event EventHandler<ScheduledEventRunEventArgs<TWorld>>? ScheduledEventRun;
// Methods
Guid ScheduleEvent(IScheduledEvent<TWorld> scheduledEvent);
void RescheduleEvent(Guid scheduledEventId, DateTime newScheduledTime);
IEnumerable<IScheduledEvent<TWorld>> GetScheduledEvents();
IScheduledEvent<TWorld>? GetScheduledEvent(Guid scheduledEventId);
bool CancelEvent(Guid scheduledEventId);
void Update(TWorld world);
}public interface IScheduledEvent<TWorld>
{
Guid Id { get; }
string? Name { get; }
string? Description { get; }
DateTime ScheduledTime { get; }
TimeSpan WarningBefore { get; }
bool HasWarning { get; }
bool IsWarningSent { get; }
bool IsDue(TWorld dateTimeProvider);
bool IsWarningDue(TWorld dateTimeProvider);
void Run(TWorld world);
void RunWarning(TWorld world);
}var event = new ScheduledEvent<MyWorld>.Builder()
.SetScheduledTime(DateTime.Now.AddHours(1))
.SetName("Hourly Backup")
.SetWarningBefore(TimeSpan.FromMinutes(5))
.SetRunAction(world => PerformBackup(world))
.SetRunWarningAction(world => NotifyUsers(world))
.Build();EventScheduler.sln
โโโ EventScheduler.Abstractions/
โ โโโ IEventScheduler.cs
โ โโโ IScheduledEvent.cs
โ โโโ IWorldDateTimeProvider.cs # Time abstraction
โโโ EventScheduler/
โ โโโ EventScheduler.cs # Main scheduler implementation
โ โโโ ScheduledEvent.cs # Event implementation with Builder
โโโ EventScheduler.Tests/ # Comprehensive test suite
โโโ EventSchedulerTests.cs # 30 unit/integration tests
โโโ Coverage/ # 98.5% code coverage reports
- Generic Programming: Works with any time provider implementation
- Builder Pattern: Fluent, readable event construction
- Observer Pattern: Event-driven notifications for execution
- Chronological Ordering: O(n) insertion maintains time-based sequence
- Abstraction Layer: Clean separation of interfaces and implementations
The library includes a comprehensive test suite with excellent coverage:
# Run all tests with coverage
.\test-suite.ps1
# Or run manually:
dotnet test --collect:"XPlat Code Coverage"- โ 30 Tests - All passing
- โ 98.5% Line Coverage
- โ 100% Method Coverage
- โ 90.4% Branch Coverage
Test categories include:
- Unit tests for core scheduling logic
- Integration tests for event lifecycle
- Warning system validation
- Edge case coverage
- Time manipulation scenarios
// Level transition events
var levelEndEvent = new ScheduledEvent<GameWorld>.Builder()
.SetScheduledTime(DateTime.Now.AddMinutes(30))
.SetWarningBefore(TimeSpan.FromSeconds(30))
.SetRunAction(world => LoadNextLevel(world))
.SetRunWarningAction(world => ShowLevelEndingMessage(world))
.Build();// Sensor maintenance scheduling
var maintenanceEvent = new ScheduledEvent<IoTDevice>.Builder()
.SetScheduledTime(DateTime.Now.AddDays(30))
.SetWarningBefore(TimeSpan.FromDays(1))
.SetRunAction(device => PerformCalibration(device))
.SetRunWarningAction(device => SendMaintenanceAlert(device))
.Build();// Production line events
var productionShift = new ScheduledEvent<Factory>.Builder()
.SetScheduledTime(DateTime.Parse("6:00 AM").AddDays(1))
.SetWarningBefore(TimeSpan.FromMinutes(15))
.SetRunAction(factory => StartProductionLine(factory))
.SetRunWarningAction(factory => AlertWorkers(factory))
.Build();// Job scheduling system
var backupJob = new ScheduledEvent<Server>.Builder()
.SetScheduledTime(DateTime.Now.Date.AddHours(2))
.SetWarningBefore(TimeSpan.FromMinutes(10))
.SetRunAction(server => ExecuteBackup(server))
.SetRunWarningAction(server => PrepareBackupResources(server))
.Build();We welcome contributions! Please follow these steps:
# Clone and build
git clone https://github.com/yourusername/eventscheduler.git
cd eventscheduler
dotnet build EventScheduler.sln
# Run tests
.\test-suite.ps1
# View coverage report (opens in browser)
start coveragereport\index.html- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Test your changes thoroughly
- Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow C# coding guidelines
- Add comprehensive unit tests for new features
- Maintain code coverage above 95%
- Use meaningful commit messages
- Update documentation for API changes
- All new code must include unit tests
- Integration tests for complex features
- Code coverage must not decrease
- All tests must pass on CI
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 EventScheduler Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
- ๐ Documentation: See this README and inline code comments
- ๐ Bug Reports: Open an issue with detailed reproduction steps
- ๐ก Feature Requests: Open an issue with use case descriptions
- ๐ฌ Discussions: GitHub Discussions for general questions
- Built with .NET Standard for maximum compatibility
- Comprehensive test coverage using xUnit and Coverlet
- Inspired by event scheduling needs in game development and simulation
EventScheduler - Precise timing, reliable execution, flexible warnings.