private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { _wes_PropertyChanged = null; _wes_StartTransition = null; _wes_BeforeExitingPreviousState = null; _wes_EndTransition = null; _timer.Tick -= _timer_Tick; _timer.Dispose(); _effectsTimer.Tick -= _effectsTimer_Tick; _effectsTimer.Dispose(); } // decrement StateMachinesDisposer.getInstance().UnRegisterSM(this); disposedValue = true; // Console.WriteLine("----->" + transitionToNewStateRecursionLevel + "-" + this.GetHashCode() + "[" + GetCurrentThreadId() + "]->DISPOSE"); } return; // we done }
/// <summary> /// Creates a new instance of this state machine. /// </summary> public StateMachine(IStateMachineHost host) { _host = new WeakReference(host); // register for dispose StateMachinesDisposer.getInstance().RegisterSM(this); _CurrentState = null; _wes_PropertyChanged = new WeakEventSource <PropertyChangedEventArgs>(); _wes_StartTransition = new WeakEventSource <TransitionEventArgs>(); _wes_BeforeExitingPreviousState = new WeakEventSource <TransitionEventArgs>(); _wes_EndTransition = new WeakEventSource <TransitionEventArgs>(); this.Initialize(); _queue = new Queue <object>(); _timer = new System.Windows.Forms.Timer(); _timer.Interval = 1; _timer.Tick += _timer_Tick; _timer.Enabled = false; _effectsQueue = new Queue <EffectAction>(); _effectsTimer = new System.Windows.Forms.Timer(); _effectsTimer.Interval = 1; _effectsTimer.Tick += _effectsTimer_Tick;; _effectsTimer.Enabled = false; }
public static StateMachinesDisposer getInstance() { if (instance == null) { instance = new StateMachinesDisposer(); } return(instance); }