Ejemplo n.º 1
0
        private void PSHttpListener_Closing(object sender, PSHttpListenerCloseEventArgs e)
        {
            PSHttpListener listener;

            if (sender != null && (listener = _listener) != null && ReferenceEquals(sender, listener))
            {
                _listener         = null;
                listener.Closing -= PSHttpListener_Closing;
            }
        }
Ejemplo n.º 2
0
        private void _Close(Action closeAction, bool isAborting)
        {
            Monitor.Enter(_syncRoot);
            try
            {
                if (_listener == null)
                {
                    if (Status == PSHttpListenerStatus.Stopped)
                    {
                        Status = PSHttpListenerStatus.Closed;
                    }
                    return;
                }

                PSHttpListenerCloseEventArgs args = new PSHttpListenerCloseEventArgs(isAborting);
                EventHandler <PSHttpListenerCloseEventArgs> eventHandler = Closing;
                try
                {
                    if (eventHandler != null)
                    {
                        eventHandler(this, args);
                    }
                }
                finally
                {
                    closeAction();
                    _listener = null;
                    Status    = PSHttpListenerStatus.Closed;
                    if ((eventHandler = Closed) != null)
                    {
                        eventHandler(this, args);
                    }
                }
            }
            finally { Monitor.Exit(_syncRoot); }
        }