Esempio n. 1
0
        /// <summary>
        /// Stops logging operations
        /// </summary>
        /// <param name="ForceStop">If this is set to true, all remaining queued messages will be dropped</param>
        public void Stop(bool ForceStop = false)
        {
            // Set whether or not the logger will ignore the remaining queue
            IgnoreQueue = ForceStop;

            // Stop the logging thread
            StopEvent.Set();
            LoggerThread.Join();
        }
Esempio n. 2
0
        // Disposes of this peer, stopping any threads
        internal void Dispose()
        {
            // Stop packet buffer thread
            StopEvent.Set();
            PacketBufferThread.Join();

            // Kill underlying P2P peer
            P2pPeer.Stop();
        }
Esempio n. 3
0
        /// <summary>
        /// Signals the service to stop.
        /// </summary>
        public void Stop()
        {
            if (StopEvent.WaitOne(0))
            {
                throw new InvalidOperationException("Service is already stopped, or is running in an unsupported mode.");
            }

            StopEvent.Set();
        }
Esempio n. 4
0
 /// <summary>
 /// Stops the server and ends all associated threads
 /// </summary>
 public void Stop()
 {
     StopEvent.Set();
     ListenerThread.Join();
     foreach (Thread worker in WorkerThreads)
     {
         worker.Join();
     }
     Listener.Stop();
 }
Esempio n. 5
0
 /// <summary>
 ///     停止任务线程
 /// </summary>
 public virtual void Stop()
 {
     if (_cancelTokenSource == null)
     {
         return;
     }
     if (_cancelTokenSource.Token.CanBeCanceled)
     {
         StopEvent.Set();
         _cancelTokenSource.Cancel();
         LogHelper.Debug($"{Name}部件停止。");
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Stops this database
        /// </summary>
        public void Stop()
        {
            // Signal a stop event
            StopEvent.Set();
            WriteThread.Join();

            // Dispose of sqlite connection
            if (Connection.State == ConnectionState.Open)
            {
                Connection.Close();
            }
            Connection.Dispose();
        }
Esempio n. 7
0
        // Stops this peer's associated threads
        internal void Stop()
        {
            // Invoke peer disconnected callback
            Server.OnPeerDisconnected?.Invoke(this, EventArgs.Empty);

            // Set stop event
            StopEvent.Set();

            // Stop write thread
            if (WriteThread.IsAlive)
            {
                WriteThread.Join();
            }

            // Stop client
            Client.Close();
        }
Esempio n. 8
0
        /// <summary>
        /// Emulates a signal instructing the service to close.  This will typically be used
        /// for unit testing services.
        /// </summary>
        /// <exception cref="TimeoutException">
        /// Thrown if the service did not exit gracefully in time before it would have
        /// been killed (e.g. by Kubernetes or Docker).
        /// </exception>
        public void Signal()
        {
            if (readyToExit)
            {
                // Application has already indicated that it has terminated.

                return;
            }

            var isTerminating = terminating;

            terminating = true;

            if (isTerminating)
            {
                return;     // Already terminating.
            }

            log?.LogInfo(() => $"Emulated stop request: [timeout={Timeout}]");

            cts.Cancel();

            lock (handlers)
            {
                foreach (var handler in handlers)
                {
                    new Thread(new ThreadStart(handler)).Start();
                }
            }

            StopEvent.Set();

            try
            {
                NeonHelper.WaitFor(() => readyToExit, Timeout);
                log?.LogInfo(() => "Process stopped gracefully.");
            }
            catch (TimeoutException)
            {
                log?.LogWarn(() => $"Process did not stop within [{Timeout}].");
                throw;
            }
        }
Esempio n. 9
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    StoppInitiated = true;
                    StopEvent.Set();
                    for (int i = 0; i < 200; i++)
                    {
                        if (Stopped)
                        {
                            break;
                        }
                        Thread.Sleep(10);
                    }
                }
                disposedValue = true;
            }
        }
Esempio n. 10
0
        public void Stop()
        {
            if (!IsListening || IsStopping)
            {
                return;
            }
            if (IsStarting)
            {
                throw new UnableToStopHostException("Cannot stop server until server has finished starting");
            }
            IsStopping = true;

            try
            {
                OnBeforeStop?.Invoke();

                StopEvent.Set();
                if (!TestingMode)
                {
                    Listening.Join();
                    foreach (var worker in Workers)
                    {
                        worker.Join();
                    }
                }
                Listener.Stop();

                if (!IsListening)
                {
                    OnAfterStop?.Invoke();
                }
            }
            catch (Exception e)
            {
                throw new UnableToStopHostException($"An error occured while trying to stop {GetType().FullName}", e);
            }
            finally
            {
                IsStopping = false;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Stops the server and ends all associated threads
        /// </summary>
        public void Stop()
        {
            // Stop polling timer
            PollingTimer.Dispose();

            // Stop our TCP listener
            Listener.Stop();

            // Stop all worker threads
            StopEvent.Set();
            foreach (var Worker in Workers)
            {
                Worker.Join();
            }

            // Remove all peers
            while (Peers.Count > 0)
            {
                RemovePeer(Peers[0]);
            }

            // Invoke on stop event handler, signalling that our threads have exited
            OnStop?.Invoke(this, EventArgs.Empty);
        }
Esempio n. 12
0
 /// <summary>
 /// Signals the service to stop.
 /// </summary>
 public virtual void Stop()
 {
     StopEvent.Set();
 }
Esempio n. 13
0
 // Disposes of this peer, stopping any threads
 internal void Dispose()
 {
     // Stop packet buffer thread
     StopEvent.Set();
     PacketBufferThread.Join();
 }
 public void Stop()
 {
     StopEvent.Set();
 }