Example #1
0
        public virtual void Stop()
        {
            if (Disposed)
            {
                throw new ObjectDisposedException("Can't call Stop on a disposed object.");
            }
            if (!IsListening || Starting || Stopping)
            {
                return;
            }

            try
            {
                Stopping = true;

                TcpListener.Stop();
                TcpListener = null;

                Stopping = false;

                OnStop?.Invoke(this);
            }
            catch (Exception e)
            {
                Logger.LogDebug(e, e.Message);
            }
            finally
            {
                Stopping = false;
            }
        }
Example #2
0
        protected Resource(MtaResource resource)
        {
            resources.Add(resource, this);
            MtaResource = resource;

            GameServer.OnStart += (Elements.ResourceRootElement source, Game.Events.OnStartEventArgs eventArgs) =>
            {
                if (eventArgs.Resource.MtaResource != this.MtaResource)
                {
                    return;
                }
                OnStart?.Invoke();
            };

            GameServer.OnPreStart += (Elements.ResourceRootElement source, Game.Events.OnPreStartEventArgs eventArgs) =>
            {
                if (eventArgs.Resource.MtaResource != this.MtaResource)
                {
                    return;
                }
                OnPreStart?.Invoke();
            };

            GameServer.OnStop += (Elements.ResourceRootElement source, Game.Events.OnStopEventArgs eventArgs) =>
            {
                if (eventArgs.Resource.MtaResource != this.MtaResource)
                {
                    return;
                }
                OnStop?.Invoke();
            };
        }
Example #3
0
        // Stop the server
        public void Stop()
        {
            // Stop the server and release resources
            _closed = true;

            try
            {
                _tcp.Server.Close();
                _tcp.Stop();
            }
            catch (Exception e)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }
            // Close all open connections
            foreach (var c in State.Instance.Clients)
            {
                c.Disconnect();
            }
            State.Instance.RemoveAllClients();
            if (OnStop != null)
            {
                OnStop.Invoke(this, null);
            }
        }
Example #4
0
        private void _ReceiveThread()
        {
            try
            {
                var isOpen     = _isOpen;
                var buffer     = new byte[BufferSize];
                var remoteIPEP = (EndPoint) new IPEndPoint(IPAddress.Any, 0);

                while (isOpen.Value)
                {
                    var recSize = _socket.ReceiveFrom(buffer, 0, BufferSize, SocketFlags.None, ref remoteIPEP);
                    var packet  = new byte[recSize];
                    Array.Copy(buffer, packet, recSize);
                    OnData?.Invoke((IPEndPoint)remoteIPEP, packet);
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                _Cleanup();
                OnStop?.Invoke(ex);
            }
        }
Example #5
0
 private void Update()
 {
     #if UNITY_EDITOR
     if (Input.GetMouseButtonDown(0))
     {
         OnStart?.Invoke();
     }
     if (Input.GetMouseButtonUp(0))
     {
         OnStop?.Invoke();
     }
     return;
     #endif
     if (Input.touches.Length > 0)
     {
         if (!_isTouched)
         {
             _isTouched = true;
             OnStart?.Invoke();
         }
     }
     else
     {
         if (_isTouched)
         {
             _isTouched = false;
             OnStop?.Invoke();
         }
     }
 }
Example #6
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                switch (args[0])
                {
                case "i":
                    break;

                case "u":
                    break;

                case "t":
                    OnStart += ServiceHelper.Run;
                    OnStop  += ServiceHelper.Stop;
                    OnStart?.Invoke();
                    Console.WriteLine("Started Ok!");
                    Console.WriteLine("Enter any key to stop.");
                    Console.ReadLine();
                    OnStop?.Invoke();
                    break;

                default:
                    break;
                }
            }
            else
            {
                RunAsWinService();
            }
        }
Example #7
0
        public void Stop()
        {
            _running = false;
            _halted  = false;

            OnStop?.Invoke(null, null);
        }
Example #8
0
        // Stop the server
        public void Stop()
        {
            // Stop the server and release resources
            _closed = true;

            try
            {
                _tcp.Server.Close();
                _tcp.Stop();
            }
            catch (Exception e)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }
            // Close all open connections
            _clients.ForEach(x => x.Disconnect());
            _clients.Clear();
            if (OnStop != null)
            {
                OnStop.Invoke(this, null);
            }
        }
 public void StartListener()
 {
     if (IsListening)
     {
         return;
     }
     if (NetworkInterface.GetIsNetworkAvailable())
     {
         tokenSource = new CancellationTokenSource();
         CancellationToken cancellationToken = tokenSource.Token;
         listeningTask = Task.Run(() =>
         {
             IsListening = true;
             try
             {
                 StartListenerAsync(cancellationToken).GetAwaiter().GetResult();;
             }
             finally
             {
                 IsListening = false;
                 OnStop?.Invoke(this, EventArgs.Empty);
             }
         }, cancellationToken);
     }
 }
Example #10
0
 internal void RaiseOnStop(string sender = null, XBMCRPC.Player.OnStop_data data = null)
 {
     if (OnStop != null)
     {
         OnStop.BeginInvoke(sender, data, null, null);
     }
 }
Example #11
0
    /// <summary>
    /// 정지
    /// </summary>
    public void Stop()
    {
        if (curAudioClip != null)
        {
            AudioClipGroup.ErasePlayingClip(curAudioClip);

            if (m_Data.m_eAudioClipGroup == E_AUDIO_CLIP_GROUP.Stop)
            {
                AudioClipGroup.Stop.OnStop(curAudioClip);
            }
            else if (m_Data.m_eAudioClipGroup == E_AUDIO_CLIP_GROUP.Bgm_Map)
            {
                AudioClipGroup.Bgm_Map.OnStop(curAudioClip);
            }
            else if (m_Data.m_eAudioClipGroup == E_AUDIO_CLIP_GROUP.Bgm_Special)
            {
                AudioClipGroup.Bgm_Special.OnStop(curAudioClip);
            }
        }

        audioSource.Stop();

        Reset();
        OnStop.Execute();
    }
Example #12
0
 public async void RaiseOnStop()
 {
     if (OnStop != null)
     {
         await OnStop.Invoke();
     }
 }
Example #13
0
 internal void RaiseOnStop(string sender = null, OnStopdataType data = null)
 {
     if (OnStop != null)
     {
         OnStop.BeginInvoke(sender, data, null, null);
     }
 }
Example #14
0
 /// <summary>
 /// 停止服务
 /// </summary>
 public void StopService()
 {
     if (apnsBroker != null)
     {
         apnsBroker.Stop();
         OnStop?.Invoke(apnsBroker);
     }
 }
Example #15
0
 /// <summary>
 /// Halts execution
 /// </summary>
 /// <param name="raiseEvent"></param>
 public void Stop(bool raiseEvent = true)
 {
     Runner.Stop();
     if (raiseEvent)
     {
         OnStop?.Invoke(this, EventArgs.Empty);
     }
 }
Example #16
0
        public async Task Stop()
        {
            OnStop?.Invoke(this, new EventArgs());

            await Scheduler.Shutdown();

            await Middleware.Disconnect();
        }
Example #17
0
 public void Stop()
 {
     if (player != null)
     {
         player.Stop();
         OnStop?.Invoke();
     }
 }
Example #18
0
 public GatewayBasedManager(string instance, Dictionary <string, string> config)
 {
     Instance = instance;
     Gateway  = GetGateway(instance, config);
     Gateway.OnDisconnected += delegate(IGateway sender) { OnStop?.Invoke(this); };
     Gateway.OnError        += delegate(IGateway sender) { OnError?.Invoke(this); };
     Gateway.OnReady        += delegate(IGateway sender) { OnReady?.Invoke(this); };
 }
Example #19
0
        public void OnStopCallback(int soundId)
        {
            TotalTime = TimeSpan.Zero;

            OnStop?.Invoke(new HowlEventArgs {
                SoundId = soundId
            });
        }
 void StopWithException(Exception ex)
 {
     // Synchronously pass the execution exception to the on stop handlers before calling
     // stop. This is done because stopping processes can trigger other exceptions and
     // we would like this to be the first one handled.
     OnStop?.Invoke(ex);
     Stop(ExitReason.Unknown);
 }
        /// <summary>
        /// 终止所有线程,清空待执行任务
        /// </summary>
        public void Stop()
        {
            switchTimer();

            //这里应该直接压入到已完成队列,而不是清掉
            while (AllTaskCount > 0)
            {
                T t;
                if (AllTasks.TryTake(out t))
                {
                    if (DoneTasks.TryAdd(t.Id, t) && DoneTasksAdded != null)
                    {
                        DoneTasksAdded.Invoke(this, new TaskArgs(t, this, t.AsyncState));
                    }
                }
            }

            Task.Factory.StartNew(() =>
            {
                while (WorkTaskCount > 0)
                {
                    //给正在执行的线程传入CancelToken
                    Parallel.ForEach(WorkTasks, (x, y) =>
                    {
                        if (x.Value.Status == TaskStatus.Canceled ||
                            x.Value.Status == TaskStatus.Faulted ||
                            x.Value.Status == TaskStatus.RanToCompletion)
                        {
                            DoneTasks.TryAdd(x.Key, x.Value);
                            if (DoneTasksAdded != null)
                            {
                                DoneTasksAdded.Invoke(this, new TaskArgs(x.Value, this, x.Value.AsyncState));
                            }
                            T t;
                            WorkTasks.TryRemove(x.Key, out t);
                        }
                        else
                        {
                            x.Value.Cancel();
                        }
                    });

                    if (OnStoping != null)
                    {
                        OnStoping.BeginInvoke(this, null, null, null);
                    }
                    System.Threading.Thread.Sleep(10);
                }
            }).ContinueWith((x) =>
            {
                if (OnStop != null)
                {
                    OnStop.BeginInvoke(this, null, null, null);
                }
                _isStoped = true;
                switchTimer();
            });
        }
    public void setDevContainer(Bodyghost.DevContainer devContainer)
    {
        int myIndex = this.transform.GetSiblingIndex();

        print("Setting devContainer (with serial " + devContainer.serialNumber + ") in frameRelay " + myIndex);
        this.devContainer = devContainer;
        OnStop?.Invoke();
        streaming = false;
    }
Example #23
0
 internal void Stop()
 {
     if (!isStopped)
     {
         isStopped = true;
         Die();
         OnStop.Invoke();
     }
 }
Example #24
0
    public void StopPulse()
    {
        if (_pulseRoutine != null)
        {
            StopCoroutine(_pulseRoutine);
        }

        OnStop.Invoke();
    }
Example #25
0
        public void Update()
        {
            Fly();

            if (_velocity == Vector3.zero)
            {
                OnStop?.Invoke(null, EventArgs.Empty);
            }
        }
Example #26
0
 private void _proc_Exited(object sender, EventArgs e)
 {
     _isStart = false;
     _mw.AppendLogln("INFO", "ffmpeg Exited.");
     OnStop?.Invoke(this, new DownloaderStopArgs
     {
         msg = "Stop"
     });
 }
Example #27
0
 public void StopServer()
 {
     _logger.LogDebug($"StopServer: hasProcess: {_process != null}");
     AbortBuild();
     while (_process != null)
     {
     }
     OnStop?.Invoke();
     _logger.LogDebug("StopServer: done");
 }
Example #28
0
        public static async Task ExecuteAsync(TimeSpan time)
        {
            OnStart?.Invoke(MODIFICATION_ID);
            SwapMouseButton(true);

            await Task.Delay(time).ConfigureAwait(false);

            SwapMouseButton(false);
            OnStop?.Invoke(MODIFICATION_ID);
        }
Example #29
0
        public void StopFlashLoop()
        {
            if (_flashRoutine != null)
            {
                StopCoroutine(_flashRoutine);
            }
            SetAlphaToDefault();

            OnStop.Invoke();
        }
Example #30
0
        public void Stop()
        {
            if (!_player.IsPlaying())
            {
                return;
            }

            OnStop?.Invoke();
            _player.Stop();
        }