This project has moved and is read-only. For the latest updates, please go here.

This repository has moved to GitHub!

Source Code on GitHub
Documentation on GitHub

Project Description
UML and Statechart inspired state machine library with hierarchical and orthogonal states. Implemented in C#. Portable assembly, runs on Windows, Mono and NETMF

Provides a state machine execution environment that serves as a foundation for both plain state machines as well as complex state machines with hierarchical (composite) and orthogonal (concurrent) states.
Fork and join transitions.
Entry-, exit-, do- and transition-actions.
Guard conditions.
Shallow history.
Run-to-completion processing.
Provides Statecharts functionality comparable to SCXML.
Low garbage object creation during runtime.
Free from runtime thread synchronization calls and timers.
Multiple state machine instances can be created from a single state machine definition.
Optional code generation based on Microsoft Visio diagrams.
Delivered as
- Portable assembly for .NET Framework 4, Silverlight 5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8 and higher versions, runs on Mono.
- Assembly for .NET Micro Framework 4.3
Detailed description on

.NET Micro Framework

StaMa perfectly matches the limitations of small devices and NETMF.
In particular...
  • StaMa doesn't use any runtime resources like timers, threads or thread synchronization objects. Clients can implement threading and synchronization according to their projects needs.
  • During state machine operation only small object allocations are necessary (mostly iterators), StaMa doesn't stress the garbage collector.
  • StaMa isn't intrinsically tied to generics which are (unfortunately) not supported by NETMF.
  • StaMa has a state machine instance concept. In case multiple instances with the same behavior are needed, there is only little memory and initialization overhead for the 2nd, 3rd, ... 100th instance. All structural and descriptive information (strings and delegates) are kept in the StateMachineTemplate, StateMachine instances are definitely flyweight.

Ticket vending machine sample
A sample demonstrates StaMa usage in the NETMF Sample Emulator



Sample complex state machine
Code and Microsoft Visio diagram is part of the release download.


Sample code for a simple state machine
Corresponding Visio diagram below.

namespace SimpleWatch
    class AppMain
        static void Main(string[] args)
            SimpleWatch watch = new SimpleWatch();


            watch = null;

    // The wrapper around the state machine controller provides the code of the entry and exit callbacks.
    class SimpleWatch
        public enum Event

        // The state machine controller.
        private StateMachine m_stateMachine = null;

        public SimpleWatch()
            StateMachineTemplate t = new StateMachineTemplate();

            //## Begin Structure
            // Generated from <file:S:\StaMa_State_Machine_Controller_Library\Samples\Clock\DlgMain.vst>
            // at 01-31-2008 23:20:24 using StaMaShapes Version 2
            t.Region("DisplayTime", false);
                t.State("DisplayDate", EnterDisplayDate, null);
                    t.Transition("RightButtonPressed", "DisplayDate", "DisplayTime", Event.RightButtonPressed, null, null);
                t.State("DisplayTime", EnterDisplayTime, null);
                    t.Transition("LeftButtonPressed", "DisplayTime", "DisplayDate", Event.LeftButtonPressed, null, null);
            //## End Structure

            m_stateMachine = t.CreateStateMachine();

            System.Console.WriteLine("After startup. Active state is {0}", m_stateMachine.ToString());

        // Forwards the trigger events to the embedded state machine
        public void SendTriggerEvent(Event ev)
            m_stateMachine.SendTriggerEvent(ev, null);
            System.Console.WriteLine("After event {0}. Active state is {1}", ev, m_stateMachine.ToString());

        // Entry callback method for state "DisplayTime".
        private void EnterDisplayDate(StateMachine stateMachine, object triggerEvent, EventArgs eventArgs)
            System.Console.WriteLine("EnterDisplayDate called.");

        // Entry callback method for state "DisplayDate".
        private void EnterDisplayTime(StateMachine stateMachine, object triggerEvent, EventArgs eventArgs)
            System.Console.WriteLine("EnterDisplayTime called.");


Comments are greatly appreciated. If You decide to evaluate or actually use StaMa in some real world application it would be excellent if You leave a note whether or not StaMa met Your needs.

Last edited Apr 3, 2016 at 11:21 AM by RolandSchneider, version 13