Skip to content

Extension Scheduling

Mikołaj Milewski edited this page Oct 27, 2026 · 1 revision

Scheduling Extension

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.

Register the extension

Call AddScheduling during Stateflows registration:

using Stateflows;
using Stateflows.StateMachines;

services.AddStateflows(stateflows => stateflows
    .AddScheduling()
    .AddStateMachines(machines => machines
        .AddStateMachine<Order>()));

Schedule an event

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.

Overview
Installation
Runtimes
   Orleans runtime
Concepts
   Events and Structural Events
   Messaging Patterns
   Validation
   Scheduling
   Observability
Behaviors
   Behavior Values
   Dependency Injection
   Behavioral Groups
   State Machines
       Concepts
           State Identity
           In-State Event Deferrals
           Evaluation of Transitions
           Exception Handling
       Building blocks
           Regions
           States
               State
               Composite State
               Orthogonal State
               Final State
           Pseudostates
               Choice
               Junction
               Fork
               Join
               History
           Transitions
               Transition
               Default Transition
               Internal Transition
   Activities
       Concepts
           Exception Handling
           Implicit Fork and Join
           Tokens
       Building blocks
           Nodes
               Action Node
               Decision Node
               Merge Node
               Initial Node
               Final Node
               Input Node
               Output Node
               Fork Node
               Join Node
               Accept Event Action Node
               Send Event Action Node
               Publish Event Action Node
               Time Event Action Node
               Data Store Node
               Structured Activity Node
               Iterative Activity Node
               Parallel Activity Node
           Flows
               Data Flow
               Control Flow
   Actions
   Entities
       Fields
       Mutations
       Projections
Extensions
   ClearScript
   FluentValidation
   JSON definitions
   Minimal APIs
   OneOf
   OpenTelemetry
   PlantUML
   Scheduling

Clone this wiki locally