/// <summary> /// Implements consistent transition between states. Throws IllegalStateException if an invalid transition is attempted. /// </summary> /// <param name="fromState">State being transitioning from</param> /// <param name="toState">State being transitioned to</param> /// <exception cref="IllegalStateException"> /// This exception is thrown if an invalid transition is attempted from <paramref name="fromState"/> to <paramref name="toState"/>. /// </exception> private void Transition(AtomicState fromState, AtomicState toState) { if (SwapState(fromState, toState)) { Debug.WriteLine("Successful transition from {0} to {1}", fromState, toState); toState.Enter(); } // else some other thread already swapped state }
/// <summary> /// Implements consistent transition between states. Throws IllegalStateException if an invalid transition is attempted. /// </summary> /// <param name="fromState">State being transitioning from</param> /// <param name="toState">State being transitioned to</param> /// <exception cref="IllegalStateException"> /// This exception is thrown if an invalid transition is attempted from <paramref name="fromState"/> to <paramref name="toState"/>. /// </exception> private void Transition(AtomicState fromState, AtomicState toState) { if (SwapState(fromState, toState)) { Debug.WriteLine("Successful transition from {0} to {1}", fromState, toState); toState.Enter(); } else { throw new IllegalStateException($"Illegal transition attempted from {fromState} to {toState}"); } }