using System;
using System.Collections.Generic;
using Wayne.Lib;
using Wayne.Lib.StateEngine;
using System.Threading;
namespace Wayne.Lib.StateEngine.Generic
{
///
/// 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.
///
///
/// Specifies the type of state data the state uses.
public abstract class AsyncWorkState : AsyncWorkState where TData : StateData
{
#region Fields
private IStateWithData stateWithData;
#endregion
#region Construction
///
/// Protected constructor.
///
///
protected AsyncWorkState(object doneTransitionType)
: base(doneTransitionType)
{
}
#endregion
#region Properties
///
/// Gets the state data for this state.
///
protected TData Data
{
get
{
if (stateWithData == null)
{
stateWithData = StateData.GetParentCompositeStateWithStateData(this);
}
return stateWithData.StateData as TData;
}
}
#endregion
}
}