Ejemplo n.º 1
0
        /// <summary>
        /// Allows stateful control of the modifications of the Session Description by blocking other updates.
        /// If called when <see cref="UnderModification"/> the call will block until the update can proceed.
        /// </summary>
        /// <returns>The <see cref="System.Threading.CancellationToken"/> which can be used to cancel the update started</returns>
        public System.Threading.CancellationToken BeginUpdate()
        {
            CheckDisposed();

            if (System.Threading.WaitHandle.SignalAndWait(m_UpdateTokenSource.Token.WaitHandle, m_Update.WaitHandle))
            {
                m_Update.Reset();
            }

            return(m_UpdateTokenSource.Token);
        }
Ejemplo n.º 2
0
 void tx()
 {
                 #if TRACE
     Console.WriteLine(new System.Diagnostics.StackTrace(true).GetFrame(0));
                 #endif
     BinaryWriter peerWriter = new BinaryWriter(peer);
     while (thread_rx.IsAlive)
     {
         byte[] messageBytes;
         while (!sendQueue.TryDequeue(out messageBytes))
         {
             mre_tx.Wait(10);
         }
         mre_tx.Reset();
         try {
             WriteMessage(peerWriter, messageBytes);
         } catch {
             PeerDisconnected();
             return;
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Calls the Disconnected multi-cast delegate when the connection is terminated
 /// </summary>
 /// <param name="remoteEndPoint">The IPEndPoint of the remote machine</param>
 /// <param name="e">The Exception object if an exception occurred</param>
 protected override void OnDisconnected(IPEndPoint remoteEndPoint, Exception e)
 {
     _mreSecured.Reset();
     _remotePublicKey = null;
     base.OnDisconnected(remoteEndPoint, e);
 }
Ejemplo n.º 4
0
        public void Monitor()
        {
            if (crashSignal.IsSet)
            {
                ProcessCrashed?.Invoke();

                Stop();

                if (options.GracePeriodEnabled)
                {
                    if (!gracePeriodTimer.Enabled)
                    {
                        gracePeriodTimer.Start();
                    }
                }
                else
                {
                    startSignal.Set();
                }

                crashSignal.Reset();
            }

            if (resetTimer.IsSet)
            {
                Stopwatch.Restart();
                resetTimer.Reset();
            }

            if (ShouldStart)
            {
                if (startSignal.IsSet)
                {
                    startSignal.Reset();
                }

                Start();
            }

            if (previousState == Status.Running && Process != null)
            {
                if (currentState != Status.Running)
                {
                    Status previousStateSnapshot = previousState;
                    Status currentStateSnapshot  = currentState;

                    Stop();

                    State = previousStateSnapshot;
                    State = currentStateSnapshot;
                }
            }
            else
            if (previousState == Status.Stopped && Process == null)
            {
                if (currentState == Status.Running)
                {
                    Start();
                }
            }
            else
            if (previousState == Status.Disabled && Process == null)
            {
                if (currentState == Status.Running)
                {
                    Start();
                }
            }

            if (currentState != Status.Disabled && HasWindow && Process != null)
            {
                Process.Refresh();

                if (options.CrashedIfUnresponsive && !Process.Responding)
                {
                    if (options.DoubleCheckEnabled)
                    {
                        if (checkSignal.IsSet)
                        {
                            if (!Process.Responding)
                            {
                                startSignal.Set();
                            }

                            checkSignal.Reset();
                        }
                        else if (!doubleCheckTimer.Enabled)
                        {
                            doubleCheckTimer.Start();
                        }
                    }
                    else
                    {
                        startSignal.Set();
                    }

                    if (startSignal.IsSet)
                    {
                        Stop();
                    }
                }

                if (options.AlwaysOnTopEnabled && Process != null && Process.Responding)
                {
                    BringToFront(true);
                }
            }
        }