Ok I am sure I am not using the state machine correctly but here is subset of sample code. This is the Appccelerate.StateMachine which used to be bbvcommon.StateMachine.
fsm.In(State.Idle)
.ExecuteOnEntry(() => {
// wake up and check if there are people still standing and if so restart
if(currentlyTalkingTo.Count() > 0)
{
fsm.Fire(Event.PersonFound);
}
})
.On(Event.PersonFound).Goto(State.WaitToRecognizePeople);
fsm.In(State.WaitToRecognizePeople)
.ExecuteOnEntry(() => {
Thread.Sleep(1000);
fsm.Fire(Event.TimeOut);
})
.On(Event.TimeOut).Goto(State.Greet);
The issue is what the best way to handle a sleep? With this code calling fsm.Stop() when shutting the application down sometimes hangs the application. Commenting all the Thread.Sleeps() in the states fixes the issue so the application successfully shuts down.
What is the recommended way of handling states that need to time out and move to another state? Sample code would be appreciated.