1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- namespace Wayne.Lib.StateEngine.Generic
- {
- /// <summary>
- /// Generic state that enables descendant classes to execute code on a worker thread
- /// when the state is active. When the processing is completed, i.e. the PerformWork returns,
- /// the state will post a transition of the type specified in the constructor.
- ///
- /// When exitting the state, we for the worker thread to complete before continuing.
- ///
- /// Descendant classes can also use the AbortWork() method to signal to the worker thread that it should exit as fast as possible.
- ///
- /// The PerformWork method should periodically check the Aborted property and if that is true, exit as fast as possible.
- /// </summary>
- /// <typeparam name="TMain"></typeparam>
- /// <typeparam name="TData">Specifies the type of state data the state uses.</typeparam>
- public abstract class AsyncWorkState<TMain, TData> : AsyncWorkState<TMain> where TData : StateData
- {
- #region Fields
- private IStateWithData stateWithData;
- #endregion
- #region Construction
- /// <summary>
- /// Protected constructor.
- /// </summary>
- /// <param name="doneTransitionType"></param>
- protected AsyncWorkState(object doneTransitionType)
- : base(doneTransitionType)
- {
- }
- #endregion
- #region Properties
- /// <summary>
- /// Gets the state data for this state.
- /// </summary>
- protected TData Data
- {
- get
- {
- if (stateWithData == null)
- {
- stateWithData = StateData.GetParentCompositeStateWithStateData<TData>(this);
- }
- return stateWithData.StateData as TData;
- }
- }
- #endregion
- }
- }
|