コード例 #1
0
ファイル: RESTServer.cs プロジェクト: gitter-badger/Grapevine
        /// <summary>
        /// Stops the server
        /// </summary>
        public void Stop()
        {
            if (!IsListening)
            {
                return;
            }
            try
            {
                OnBeforeStop?.Invoke();

                _stop.Set();
                _listening.Join();
                foreach (Thread worker in _workers)
                {
                    worker.Join();
                }
                _listener.Stop();

                if (!IsListening)
                {
                    OnAfterStop?.Invoke();
                }
            }
            catch (Exception e)
            {
                throw new CantStartHostException($"An error occured while trying to stop {GetType().FullName}", e);
            }
        }
コード例 #2
0
ファイル: SocketConnector.cs プロジェクト: pents/FileGate
 public Task StopClient()
 {
     OnBeforeStop?.Invoke();
     _tokenSource.Cancel();
     _client.Dispose();
     OnAfterStop?.Invoke();
     return(Task.CompletedTask);
 }
コード例 #3
0
 public void Stop()
 {
     OnBeforeStop?.Invoke(this, EventArgs.Empty);
     if (Bass.BASS_ChannelStop(ChannelHandle))
     {
         Bass.BASS_StreamFree(ChannelHandle);
         ChannelHandle = 0;
         IsActive      = false;
     }
     OnAfterStop?.Invoke(this, EventArgs.Empty);
 }
コード例 #4
0
        protected void OnBeforeStopping()
        {
            OnBeforeStop?.Invoke();
            if (BeforeStopping == null)
            {
                return;
            }
            var exceptions = InvokeServerEventHandlers(BeforeStopping.GetInvocationList().Reverse().Cast <ServerEventHandler>());

            if (exceptions.Count > 0)
            {
                throw new AggregateException(exceptions);
            }
        }
コード例 #5
0
        public void Stop()
        {
            if (_host != null)
            {
                lock (_hostSync)
                {
                    if (_host != null)
                    {
                        var exceptions = new List <Exception>();

                        try
                        {
                            OnBeforeStop?.Invoke(this, EventArgs.Empty);
                        }
                        catch (Exception exception)
                        {
                            exceptions.Add(exception);
                        }

                        try
                        {
                            _host.Dispose();
                        }
                        catch (Exception exception)
                        {
                            exceptions.Add(exception);
                        }
                        finally
                        {
                            _host = null;
                        }

                        try
                        {
                            OnAfterStop?.Invoke(this, EventArgs.Empty);
                        }
                        catch (Exception exception)
                        {
                            exceptions.Add(exception);
                        }

                        if (exceptions.Count > 0)
                        {
                            throw new AggregateException(Resources.CannotStopServiceCorrectly, exceptions);
                        }
                    }
                }
            }
        }
コード例 #6
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;
            }
        }