Example #1
0
        /// <summary>
        /// Raises the ConnectionStateChanged event
        /// </summary>
        /// <param name="state">The new connection state</param>
        /// <remarks>Note to inheritors:  be sure to call the base implementation to ensure the event is raised.</remarks>
        protected virtual void OnConnectionStateChanged(ChannelConnectionState state)
        {
            ChannelConnectionStateChangedEventHandler tempEvent = ConnectionStateChanged;

            if (tempEvent != null)
            {
                var e = new ChannelConnectionStateChangedEventArgs(state);
                tempEvent.Invoke(this, e);
            }
        }
Example #2
0
        /// <summary>
        /// Set a new connection state, raising an event if it has changed.
        /// </summary>
        /// <param name="newState"></param>
        private void SetConnectionState(ChannelConnectionState newState)
        {
            bool stateChanged = false;

            //while we can atomically read or write connection state, we want to a get and set.
            lock (m_Lock)
            {
                if (newState != m_ConnectionState)
                {
                    stateChanged      = true;
                    m_ConnectionState = newState;
                }

                System.Threading.Monitor.PulseAll(m_Lock);
            }

            //only raise the event if we changed the state, and now we're outside of the lock so it's safe.
            if (stateChanged)
            {
                OnConnectionStateChanged(newState);
            }
        }
 internal ChannelConnectionStateChangedEventArgs(ChannelConnectionState state)
 {
     State = state;
 }