Question: **Update:**

Again thanks for the examples, they have been very helpful and with the following, I don't mean
to take anything away from them.

Aren't the currently given examples, as far as I understand them & state-machines, only half of what we usually understand by a state-machine?  

In the sense that the examples do change state but that's only represented by changing the value of a variable (and allowing different value- changes in different states), while usually, a state machine should also change its behavior, and behavior not (only) in the sense of allowing different value changes for a variable depending on the state, but in the sense of allowing different methods to be executed for different states.

Or do I have a misconception of state machines and their common use?

---

**Original question:**

I found this discussion about [state machines & iterator blocks in c#](https://stackoverflow.com/questions/1406986/does-c-include-finite-state-machines) and tools to create state machines and whatnot for C#, so I found a lot of abstract stuff but as a noob, all of this is a little confusing.

So it would be great if someone could provide a C# source code-example that realizes a simple state machine with perhaps 3,4 states, just to get the gist of it.

Answer: 
Today i deep in State Design Pattern.
I did and tested ThreadState, which equal (+/-) to Threading in C#, as described in picture from [Threading in C#](http://www.albahari.com/threading/part2.aspx)

![enter image description here](https://i.stack.imgur.com/mZvLz.png)

You can easly add new states, configure moves from one state to other is very easy becouse it incapsulated in state implementation

Implementation and using at: [Implements .NET ThreadState by State Design Pattern](https://web.archive.org/web/20140102140708/http://simpledesignpatterns.blogspot.co.il/2013/11/implements-net-threadstate-by-state.html)
You can use my solution, this is the most convenient way. It’s also free.

Create state machine in **three** steps :

**1.** Create scheme in [node editor](https://github.com/SimpleStateMachine/SimpleStateMachineNodeEditor) and load it in your project using [library](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary)

```
StateMachine stateMachine = new StateMachine("scheme.xml");

```

**2.** Describe your app logic on events⚡

```
stateMachine.GetState("State1").OnExit(Action1);
stateMachine.GetState("State2").OnEntry(Action2);
stateMachine.GetTransition("Transition1").OnInvoke(Action3);
stateMachine.OnChangeState(Action4);

```

**3.** Run the state machine

```
stateMachine.Start();

```

Links:

Node editor: <https://github.com/SimpleStateMachine/SimpleStateMachineNodeEditor>

Library: <https://github.com/SimpleStateMachine/SimpleStateMachineLibrary>