When Ranger is in a state where Shutdown() cannot be called yet, then the application will:
Never use a
loop that checks the Ranger state. The OS message pump needs to run
normally for the Ranger state transitions to complete properly.
There are a few scenarios which may require a couple of state transitions to end up in a state where Shutdown() is allowed.
For example, if Ranger is handling an exception.
So more than one state changing functions, may be required to bring Ranger into the target state.
One
of the easiest ways to avoid problems is to disable the ability for the
user to exit the application when Ranger is in a state where Shutdown()
cannot be called. So if items are feeding for example, they user would
not be given the ability to exit (by as disabling the "exit" button).
However, once feeding has stopped, and Ranger is in the ReadyToFeed
state, then the option to exit the application can be enabled.