/// <summary>
        /// Stops the background thread that is receiving messages for the connection
        /// </summary>
        /// <param name="disconnect">A flag that indicates whether the connection should be closed</param>
        public virtual void EndReceiving(bool disconnect)
        {
            _disconnectOnStop = disconnect;

            // signal a stop, we might get lucky and ease the thread out
            if (_stopEvent != null)
            {
                _stopEvent.Set();
            }

            // and finally kill the receiving thread
            if (_thread != null)
            {
                _thread.Dispose();
                _thread = null;
            }
            _stopEvent = null;
        }
Example #2
0
        /// <summary>
        /// Stops the server (No incoming connections will be accepted while the server is stopped)
        /// </summary>
        /// <returns></returns>
        public bool Stop(bool endCurrentSessions)
        {
            try
            {
                if (endCurrentSessions)
                {
                    this.EndCurrentSessions();
                }

                if (_thread != null)
                {
                    _thread.Dispose();
                    _thread = null;
                }

                if (_listeningSocket != null)
                {
                    try
                    {
                        // shutdown and close the socket
                        //             _socket.Shutdown(SocketShutdown.Both);
                        _listeningSocket.Close();
                    }
                    catch (SocketException ex)
                    {
                        Debug.WriteLineIf(_verbose, string.Format("An exception was encountered while attempting to shutdown & close the server's listening socket.\n\t{0}", ex.ToString()), TraceCategory);
                    }
                    _listeningSocket = null;
                }

                _isStarted  = false;
                _dispatcher = null;

                EventManager.Raise <EventArgs>(this.ServerStopped, this, EventArgs.Empty);

                return(true);
            }
            catch (Exception ex)
            {
                this.OnException(this, new ExceptionEventArgs(ex));
            }
            return(false);
        }
Example #3
0
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{			
			if (disposing)
			{
				this.IsScrolling = false;

				if (_thread != null)
				{
					_thread.Dispose();
					_thread = null;
				}

				if (_image != null)
				{
					_image.Dispose();
					_image = null;
				}				
			}
			base.Dispose( disposing );			
		}
        /// <summary>
        /// Stops the server (No incoming connections will be accepted while the server is stopped)
        /// </summary>
        /// <returns></returns>
        public bool Stop(bool endCurrentSessions)
        {
            try
            {
                if (endCurrentSessions)
                {
                    this.EndCurrentSessions();
                }

                if (_thread != null)
                {
                    _thread.Dispose();
                    _thread = null;
                }

                if (_listeningSocket != null)
                {
                    try
                    {
                        // shutdown and close the socket
                        //             _socket.Shutdown(SocketShutdown.Both);
                        _listeningSocket.Close();
                    }
                    catch (SocketException ex)
                    {
                        Debug.WriteLineIf(_verbose, string.Format("An exception was encountered while attempting to shutdown & close the server's listening socket.\n\t{0}", ex.ToString()), MY_TRACE_CATEGORY);
                    }
                    _listeningSocket = null;
                }

                _dispatcher = null;

                return(true);
            }
            catch (Exception ex)
            {
                this.OnException(this, new ExceptionEventArgs(ex));
            }
            return(false);
        }