private async Task ReceiveSpinner(CancellationToken ct)
        {
            while (!ct.IsCancellationRequested)
            {
                try
                {
                    var msg = await ReceiveMessage(ct);

                    await _rxPipeline.Add(msg, ct);
                }
                catch (TaskCanceledException)
                {
                    // Continue, as the next check for the cancelled token is then
                    // performed and the loop is exited.
                    continue;
                }
                catch (BrokenFrameException ex)
                {
                    OnBrokenFrame?.Invoke(this, ex.BrokenFrame, ex.InnerException);
                }
                catch (Exception ex)
                {
                    OnStopped?.Invoke(this, ex);
                    break;
                }
            }

            Running = false;
            _stream = null;
        }
Exemplo n.º 2
0
        /// <summary>Stops accepting new messages for immediate delivery. </summary>
        /// <param name="immediate">
        ///     If <code>true</code>, the service immediately redirects all messages in the queue to the
        ///     backlog; emails that are queued after a stop call are always sent to the backlog. Otherwise, all queued messages
        ///     are sent before closing the producer to additional messages.
        /// </param>
        public virtual void Stop(bool immediate = false)
        {
            if (!Running)
            {
                return;
            }

            _buffer.CompleteAdding();

            if (!immediate)
            {
                WaitForEmptyBuffer();
            }
            else
            {
                FlushBacklog();
            }

            Running = false;
            _uptime.Stop();
            if (_internal)
            {
                _buffer = new BlockingCollection <T>();
            }

            OnStopped?.Invoke();
        }
Exemplo n.º 3
0
        public void Stop()
        {
            alive = false;

            acceptor.Abort();

            if (listener != null)
            {
                listener.Stop();
                listener = null;
            }

            while (runner.IsAlive)
            {
                Thread.Sleep(10);
            }

            lock (clientList)
            {
                foreach (TcpClient client in clientList)
                {
                    client.Close();
                }
            }

            if (OnStopped != null)
            {
                OnStopped.Invoke();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Stops accepting connections.
        /// But does not disconnect connected clients.
        /// In order to disconnect all clients, you need to do it manually
        /// You can use a ClientContainer implementation to do it easily
        /// </summary>
        public void Stop()
        {
            IsRunning = false;

            //stop server time creator timer
            if (_timeTimer != null)
            {
                _timeTimer.Stop();
                _timeTimer.Dispose();
                _timeTimer = null;
            }

            //stop websocket pinger
            if (Pinger != null)
            {
                Pinger.Stop();
                Pinger = null;
            }

            //stop and dispose all listeners (for all ports)
            foreach (ConnectionHandler handler in _handlers)
            {
                handler.Dispose();
            }

            _handlers.Clear();

            OnStopped?.Invoke(this);
        }
Exemplo n.º 5
0
        internal override void InvokeEvent(ServerType type, IConnection conn, IMessage msg)
        {
            switch (type)
            {
            case ServerType.Started:
                OnStarted?.Invoke(conn, msg);
                break;

            case ServerType.Accepted:
                OnAccepted?.Invoke(conn, msg);
                break;

            case ServerType.Sended:
                OnSended?.Invoke(conn, msg);
                break;

            case ServerType.Received:
                OnRecieved?.Invoke(conn, msg);
                break;

            case ServerType.Disconnected:
                OnDisconnected?.Invoke(conn, msg);
                break;

            case ServerType.Stopped:
                OnStopped?.Invoke(conn, msg);
                break;
            }
        }
Exemplo n.º 6
0
 public void Stop()
 {
     browser.Stop();
     this.IsBusy = false;
     OnBusyStatusChange?.Invoke(this.IsBusy, new EventArgs());
     OnStopped?.Invoke(this, new EventArgs());
 }
Exemplo n.º 7
0
        public override void Stop()
        {
            if (Listener == null)
            {
                return;
            }
            if (!Listener.Running)
            {
                return;
            }

            try
            {
                Listener?.Stop();

                OnStopped?.Invoke(new NetClientEventArgs <ITcpConnection>(this));
            }
            catch (Exception ex)
            {
                OnException?.Invoke(new NetClientEventArgs <ITcpConnection>(this)
                {
                    Exception = ex
                });
            }
        }
Exemplo n.º 8
0
        private void _stopped()
        {
            _worker = null;
            _cancellationTokenSource?.Dispose();
            _cancellationTokenSource = null;

            Status = WorkerStatus.Stopped;

            OnStopped?.Invoke(this, new EventArgs());
        }
Exemplo n.º 9
0
 public void StopTimer(bool dispose)
 {
     timer.Stop();
     counter = 0;
     OnStopped?.Invoke();
     if (dispose)
     {
         timer.Dispose();
     }
 }
Exemplo n.º 10
0
        public void Stop()
        {
            if (!isStart)
            {
                return;
            }

            isStart = false;
            OnStopped?.Invoke();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Remove all BehaviourNode related Event listeners
        /// </summary>
        public void RemoveAllListeners()
        {
            OnStarted.RemoveAllListeners();
            OnStartedSilent.RemoveAllListeners();

            OnStopping.RemoveAllListeners();
            OnStoppingSilent.RemoveAllListeners();

            OnStopped.RemoveAllListeners();
            OnStoppedSilent.RemoveAllListeners();
        }
Exemplo n.º 12
0
        private void StopMoving()
        {
            _state      = CubimalState.Settled;
            _isSettling = false;

            _navMeshAgent.enabled = false;
            _animator.SetBool(IsRacingBool, false);

            _key.StopUnwinding();
            _destination = Vector3.zero;

            OnStopped?.Invoke();
        }
Exemplo n.º 13
0
        public async Task Stop()
        {
            await Task <Oridashi.Fhir.Host.Configuration> .Run(new Action(() =>
            {
                if (host != null)
                {
                    host.Stop();
                }


                running = false;
                OnStopped?.Invoke();
            }));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Shuts down the client, disconnecting from the IRC server, and shutting down any of our threads.
        /// </summary>
        public void Stop()
        {
            lock (controlSyncLock)
            {
                // Ensure client is killed dead
                if (client != null)
                {
                    if (client.IsConnected)
                    {
                        try
                        {
                            client.Disconnect();
                        }
                        catch (Exception) { }
                    }
                }

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

                // Switch status & raise event if we aren't already in stopped state
                if (Status != ClientStatus.Stopped)
                {
                    TmiLog.Log("Stopping client...");

                    if (OnStopped != null)
                    {
                        OnStopped.Invoke(this, new EventArgs());
                    }
                }

                Status = ClientStatus.Stopped;

                // Kick the queue thread so it quits faster
                if (channelJoinQueueThread != null)
                {
                    try
                    {
                        channelJoinQueueThread.Interrupt();
                    }
                    catch (Exception) { }

                    channelJoinQueueThread = null;
                }
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// Stops the server.
 /// </summary>
 public void Stop()
 {
     if (running)
     {
         lock (runningLock)
         {
             if (running)
             {
                 running = false;
                 ClearRunningState();
                 OnStopped?.Invoke(this);
             }
         }
     }
 }
Exemplo n.º 16
0
        public void Stop()
        {
            if (!IsRunning)
            {
                return;
            }

            _isRunning = false;
            Address    = null;
            Port       = null;
            _serverSocket?.Stop();
            _pubSubRouter.Dispose();
            _thread.Join();
            _thread = null;
            OnStopped?.BeginInvoke(null, null);
        }
    public void Stop()
    {
        if (state == UpdatorState.Stop)
        {
            return;
        }
        state = UpdatorState.Stop;

#if UNITY_EDITOR
        // in case value changed in GameManager
        maxForceMagnitude = Mathf.Max(1, GameManager.Instance.MaxForce);
#endif

        //force = ForceEvaluator.Evaluate(maxForce, currentScale.x, EvaluateMethod.Parabola);
        forceMagnitude = ForceEvaluator.Evaluate(maxForceMagnitude, currentScale.x, EvaluateMethod.Linear);
        OnStopped.Invoke(new StoppedEventArgs(state, currentScale.x, forceMagnitude));
    }
Exemplo n.º 18
0
        public void Stop()
        {
            disconnectPing.Stop();
            BroadcastLine(COMMAND_DISCONNECT);
            Host.Stop();
            Host = null;

            foreach (var client in Clients)
            {
                DisconnectClient(client);
            }

            Clients.Clear();

            InvokeOutput("Server Stopped.");
            OnStopped?.Invoke();
        }
Exemplo n.º 19
0
    private void FixedUpdate()
    {
        if (netForceMagnitude <= 0)
        {
            OnStopped.Invoke();
            hasStopped = true;
            return;
        }

        if (!hasStarted)
        {
            OnStarted.Invoke();
            hasStarted = true;
        }

        AddForce(netForceMagnitude, moveDirection);
        UpdateNetForce();
    }
Exemplo n.º 20
0
        public virtual bool Stop()
        {
            try
            {
                ScheduledTask.StopSchedule();

                OnStopped?.Invoke(this, new WorkerStoppedEventArgs());

                Store($"{Name} has stopped at {DateTime.Now}");

                return(true);
            }
            catch (Exception exception)
            {
                WorkerLogger.Error("", exception);
                return(false);
            }
        }
Exemplo n.º 21
0
 public override void Stop()
 {
     if (Clients.Count > 0)
     {
         Dictionary <string, object> arguments = new Dictionary <string, object>();
         arguments.Add("Imaging", "Stop");
         foreach (ClientObject client in Clients.Values)
         {
             client.Connections["Main"].Write(Password, new Command(client.Information, Information, CommandType.Custom)
             {
                 Properties = arguments
             });
         }
     }
     try { base.Stop(); }
     catch (Exception error) { throw error; }
     OnStopped?.BeginInvoke(result => { try { OnStopped.EndInvoke(result); } catch { } }, null);
     Port = -1;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Forces the node to be INACTIVE, bypassing the STOPPING state.
 /// This is a very dangerous method that can cause unexpected behaviour!
 /// </summary>
 /// <param name="success">If the node was successful</param>
 /// <param name="silent">If true will not invoke the OnStarted event</param>
 /// <returns></returns>
 public virtual bool StopNode(bool success, bool silent = false)
 {
     if (this.State != NodeState.INACTIVE)
     {
         this.State  = NodeState.INACTIVE;
         this.Result = success;
         if (!silent)
         {
             OnStopped.Invoke(success);
             Parent?.OnChildNodeStopped.Invoke(this, success);
         }
         else
         {
             OnStoppedSilent.Invoke(success);
             Parent?.OnChildNodeStoppedSilent.Invoke(this, success);
         }
         return(true);
     }
     return(false);
 }
Exemplo n.º 23
0
        public void SafeWorkerDelegate()
        {
            if (_thread == null)
            {
                return;
            }

            Logger.Debug("Thread {0}: {1} Started", _thread.ManagedThreadId, _thread.Name);

            while (_working)
            {
                try
                {
                    Thread.Sleep(Math.Max(50, WaitTime));

                    if (_worker == null)
                    {
                        continue;
                    }

                    if (_worker.Invoke())
                    {
                        _working = false;
                    }
                }
                catch (ThreadAbortException ex)
                {
                    _working = false;
                    Logger.Debug("Aborting Thread: {0}, StateInfo={1}", _thread.ManagedThreadId, ex.ExceptionState);
                    Thread.ResetAbort();
                }
                catch (Exception ex)
                {
                    Logger.Log("Error in Thread {0}: {1} {2}", _thread.ManagedThreadId, _thread.Name, ex);
                }
            }

            Logger.Debug("Thread {0}: {1} Finished", _thread.ManagedThreadId, _thread.Name);

            OnStopped.Invoke();
        }
Exemplo n.º 24
0
        public void Stop()
        {
            if (IsStopping || !IsStarted)
            {
                return;
            }

            IsStopping = true;

            OnStopping?.Invoke();
            OnContextStopping?.Invoke(this);

            IsStopping = false;
            IsStarted  = false;

            OnStopped?.Invoke();
            OnContextStopped?.Invoke(this);

            DisposeModules();
            DisposeExtensions();
        }
Exemplo n.º 25
0
        /// <summary>
        /// 停止NodeServer
        /// </summary>
        public Task StopAsync()
        {
            if (server == null)
            {
                logger.LogDebug("Server instance is not start.");
                return(Task.CompletedTask);
            }

            OnStopping?.Invoke(new NodeServerStopEventArg(config.Host, config.Port, RouteManager.GetAllRoutes()));

            return(server.CloseAsync().ContinueWith(task =>
            {
                if (task.Exception != null)
                {
                    logger.LogError(task.Exception, $"Server closing has error. Host={config.Host}, Port={config.Port}, ExceptionMessage={task.Exception.InnerException.Message}, ExceptionStackTrace={task.Exception.InnerException.StackTrace}");
                    return;
                }
                logger.LogInformation("Server closed");
                OnStopped?.Invoke(new NodeServerStopEventArg(config.Host, config.Port, RouteManager.GetAllRoutes()));
            }));
        }
Exemplo n.º 26
0
 private void CompletedTask()
 {
     while (_run)
     {
         try
         {
             var activeThread = Active;
             if (activeThread == 0 && _runnerStatus == RunnerStatus.Stopped)
             {
                 _run = false;
                 _stopwatch.Stop();
                 _datapool.Clear();
                 _cts.Dispose();
                 try { OnStopped?.Invoke(this, new StopEventArgs()
                     {
                         WordList = _wordlist, Save = _save, Log = _log
                     }); } catch (Exception ex) { OnException?.Invoke(this, new ExceptionEventArgs()
                     {
                         Location = "OnStopped", Exception = ex, Log = _log
                     }); }
             }
             else if (activeThread == 0)
             {
                 _run = false;
                 _stopwatch.Stop();
                 _datapool.Clear();
                 _cts.Dispose();
                 _runnerStatus = RunnerStatus.Completed;
                 try { OnCompleted?.Invoke(this, new EventArgs()); } catch (Exception ex) { OnException?.Invoke(this, new ExceptionEventArgs()
                     {
                         Location = "OnCompleted", Exception = ex, Log = _log
                     }); }
             }
         }
         catch
         {
         }
         Thread.Sleep(100);
     }
 }
Exemplo n.º 27
0
        public void Run(GimmickValue value, DateTime current)
        {
            if (playableDirector == null)
            {
                return;
            }
            if (value.TimeStamp <= LastTriggeredAt)
            {
                return;
            }
            if (playTimelineGimmick != null && value.TimeStamp <= playTimelineGimmick.LastTriggeredAt)
            {
                return;
            }
            LastTriggeredAt = value.TimeStamp;

            playableDirector.time = playableDirector.initialTime;
            playableDirector.Evaluate();
            playableDirector.Stop();

            OnStopped?.Invoke();
        }
Exemplo n.º 28
0
        void Instance_CurrentStateChanged(object sender, RoutedEventArgs e)
        {
            switch (Instance.CurrentState)
            {
            case MediaElementState.Closed:
                StatusChanged?.Invoke(this, MediaState.NothingSpecial);
                break;

            case MediaElementState.Opening:
                StatusChanged?.Invoke(this, MediaState.Opening);
                break;

            case MediaElementState.Buffering:
                StatusChanged?.Invoke(this, MediaState.Buffering);
                break;

            case MediaElementState.Playing:
                StatusChanged?.Invoke(this, MediaState.Playing);
                dispatchTimer?.Start();
                break;

            case MediaElementState.Paused:
                StatusChanged?.Invoke(this, MediaState.Paused);
                dispatchTimer?.Stop();
                break;

            case MediaElementState.Stopped:
                StatusChanged?.Invoke(this, MediaState.Stopped);
                dispatchTimer?.Stop();
                OnStopped?.Invoke(this);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 public void InvokeOnStopped(int exitCode)
 {
     OnStopped?.Invoke(exitCode);
 }
Exemplo n.º 30
0
 protected virtual void OnStoppedHandler(TEventArgs args) => OnStopped?.Invoke(args);