/// <summary>
        /// Start monitor the socket, the method doesn't start a new thread and will block until the monitor poll is stopped
        /// </summary>
        public void Start()
        {
            // in case the sockets is created in another thread
            Thread.MemoryBarrier();

            if (IsRunning)
            {
                throw new InvalidOperationException("Monitor already started");
            }

            if (m_attachedPoller != null)
            {
                throw new InvalidOperationException("Monitor attached to a poller");
            }

            InternalStart();

            try
            {
                while (!m_cancellationTokenSource.IsCancellationRequested)
                {
                    MonitoringSocket.Poll(Timeout);
                }
            }
            finally
            {
                InternalClose();
            }
        }
Example #2
0
 private void InternalClose()
 {
     try
     {
         MonitoringSocket.Disconnect(Endpoint);
     }
     catch (Exception)
     {}
     finally
     {
         IsRunning = false;
         m_isStoppedEvent.Set();
     }
 }
        public void Dispose()
        {
            if (m_attachedPoller != null)
            {
                DetachFromPoller();
            }
            else if (!m_isStoppedEvent.WaitOne(0))
            {
                Stop();
            }

            if (m_isOwner)
            {
                MonitoringSocket.Dispose();
            }
        }
Example #4
0
        /// <summary>
        /// Release and dispose of any contained resources.
        /// </summary>
        /// <param name="disposing">true if releasing managed resources</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            if (m_attachedPoller != null)
            {
                DetachFromPoller();
            }
            else if (!m_isStoppedEvent.WaitOne(0))
            {
                Stop();
            }

            m_isStoppedEvent.Close();

            if (m_isOwner)
            {
                MonitoringSocket.Dispose();
            }
        }
 private void InternalClose()
 {
     m_isStoppedEvent.Set();
     IsRunning = false;
     MonitoringSocket.Disconnect(Endpoint);
 }
 private void InternalStart()
 {
     m_isStoppedEvent.Reset();
     IsRunning = true;
     MonitoringSocket.Connect(Endpoint);
 }