Repository navigation
6.8. Scheduling
Stateflows.Extensions.Scheduling provides dynamic, imperative scheduling of events. It complements the core's declarative TimeEvent triggers: the extension can schedule any event payload for a selected Behavior without adding a time trigger to a State Machine transition or Activity node. For the core model-based feature, see Scheduling.
Call AddScheduling during Stateflows registration:
using Stateflows;
using Stateflows.StateMachines;
services.AddStateflows(stateflows => stateflows
.AddScheduling()
.AddStateMachines(machines => machines
.AddStateMachine<Order>()));The scheduling methods target the Behavior handle on which they are called and return a success flag with a schedule ID:
var (success, scheduleId) =
await behavior.ScheduleDelayAsync(
TimeSpan.FromMinutes(5),
new ReservationExpired());
if (success)
{
await behavior.UnscheduleAsync(scheduleId);
}The extension exposes ScheduleTimeAsync, ScheduleDelayAsync, ScheduleIntervalAsync, and ScheduleCronAsync. Use the returned ID with UnscheduleAsync to cancel a schedule.
The scheduler is itself a State Machine; its state and pending schedules use Stateflows' configured runtime and storage. Configure persistence and hosting according to the application's runtime if schedules must survive process restarts. Cron expressions are evaluated using NCrontab. See the extension source for request types and scheduling behavior.
Home page Support Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0. © by Mikołaj Milewski, 2026