Esempio n. 1
0
        public void Dispose()
        {
            if (TokenSource != null)
            {
                if (!TokenSource.IsCancellationRequested)
                {
                    TokenSource.Cancel();
                    TokenSource.Dispose();
                }
            }

            if (_sslStream != null)
            {
                _sslStream.Close();
            }

            if (_networkStream != null)
            {
                _networkStream.Close();
            }

            if (_tcpClient != null)
            {
                _tcpClient.Close();
                _tcpClient.Dispose();
            }

            SendLock.Dispose();
            ReceiveLock.Dispose();
        }
        /// <inheritdoc />
        /// <summary>
        /// Properly dispose the class.
        /// </summary>
        public override void Dispose()
        {
            try
            {
                if (!Disposed)
                {
                    TokenSource.Cancel();
                    TokenSource.Dispose();
                    IsRunning = false;
                    Listener.Dispose();
                    CanAcceptConnections.Dispose();
                    _keepAliveTimer.Enabled = false;
                    _keepAliveTimer.Dispose();

                    foreach (var id in ConnectedClients.Keys.ToList())
                    {
                        Close(id);
                    }

                    ConnectedClients = new Dictionary <int, IClientMetadata>();
                    TokenSource.Dispose();
                    Disposed = true;
                    GC.SuppressFinalize(this);
                }
                else
                {
                    throw new ObjectDisposedException(nameof(SimpleSocketListener), "This object is already disposed.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
Esempio n. 3
0
        public void Dispose()
        {
            if (TokenSource != null)
            {
                if (!TokenSource.IsCancellationRequested)
                {
                    TokenSource.Cancel();
                    TokenSource.Dispose();
                }
            }

            if (_SslStream != null)
            {
                _SslStream.Close();
            }

            if (_NetworkStream != null)
            {
                _NetworkStream.Close();
            }

            if (_TcpClient != null)
            {
                _TcpClient.Close();
                _TcpClient.Dispose();
            }
        }
Esempio n. 4
0
 private void BusyableDialogWindow_Closed(object sender, EventArgs e)
 {
     // TokenSources need to be disposed, so here it is.
     if (TokenSource != null)
     {
         TokenSource.Dispose();
     }
 }
Esempio n. 5
0
 public void DisposeToken()
 {
     if (TokenSource is object)
     {
         TokenSource.Dispose();
         TokenSource = null;
     }
 }
 /// <summary>
 /// Disposes this object
 /// </summary>
 public void Dispose()
 {
     if (isDisposed)
     {
         return;
     }
     TokenSource.Dispose();
     isDisposed = true;
 }
Esempio n. 7
0
 public void Dispose()
 {
     if (TokenSource is null)
     {
         return;
     }
     TokenSource.Cancel();
     TokenSource.Dispose();
     TokenSource = null;
 }
Esempio n. 8
0
        public void Disconnect()
        {
            if (!Connected)
            {
                Logger.Log(Logger.Level.Info, "A disconnection request was made while already disconnected.  Skipping.");
                return;
            }

            Logger.Log(Logger.Level.Info, "Attempting to disconnect from the remote socket.");

            Connected = false;

            if (TokenSource != null)
            {
                Logger.Log(Logger.Level.Debug, "Cancelling and disposing of TokenSource");
                if (!TokenSource.IsCancellationRequested)
                {
                    TokenSource.Cancel();
                }
                TokenSource.Dispose();
                TokenSource = null;
            }
            else
            {
                Logger.Log(Logger.Level.Debug, "TokenSource already cancelled.  Skipping.");
            }

            if (NetworkStream != null)
            {
                // Network stream must be disconnected and disposed separately
                Logger.Log(Logger.Level.Debug, "Closing and disposing of network stream");
                NetworkStream.Close();
                NetworkStream.Dispose();
                NetworkStream = null;
            }
            else
            {
                Logger.Log(Logger.Level.Debug, "Network stream already closed.  Skipping.");
            }

            if (Client != null)
            {
                Logger.Log(Logger.Level.Debug, "Closing and disposing of socket instance");
                Client.Close();
                Client.Dispose();
                Client = null;
            }
            else
            {
                Logger.Log(Logger.Level.Debug, "Socket instance already closed.  Skipping");
            }

            Logger.Log(Logger.Level.Info, "Disconnected from the remote socket");
        }
Esempio n. 9
0
        /// <summary>
        /// Safely close client and break all connections to server.
        /// </summary>
        public override void Dispose()
        {
            Close();
            ConnectedMre.Dispose();
            SentMre.Dispose();
            KeepAliveTimer.Enabled = false;
            KeepAliveTimer.Dispose();
            TokenSource.Dispose();

            GC.SuppressFinalize(this);
        }
Esempio n. 10
0
 public void Dispose()
 {
     _logger.LogInformation("Server: Stop listening...");
     if (TokenSource is null)
     {
         return;
     }
     TokenSource.Cancel();
     TokenSource.Dispose();
     TokenSource = null;
 }
Esempio n. 11
0
 public void Dispose()
 {
     if (!IsDisposing)
     {
         IsDisposing = true;
         Status      = IndexStatus.Disposing;
         TokenSource.Cancel();
         TokenSource.Dispose();
         FilesWatcher?.Dispose();
         IndexBuilder?.Dispose();
         Status = IndexStatus.Disposed;
     }
 }
Esempio n. 12
0
        //public static string DateUniqeServ = "";


        protected override void OnDisappearing()
        {
            try
            {
                TokenSource.Cancel();
                TokenSource.Dispose();
            }
            catch
            {
            }
            MessagingCenter.Send <Object>(this, "AutoUpdate");
            base.OnDisappearing();
        }
Esempio n. 13
0
        private void kopatorMainForm_FormClosing(object oSender, FormClosingEventArgs oArgs)
        {
            if (IsProcessing)
            {
                oArgs.Cancel = true;
                return;
            }

            Settings.Default.Cut     = cbMove.Checked;
            Settings.Default.TabPage = oTabControl.SelectedIndex;
            Settings.Default.Save();

            TokenSource?.Dispose();
        }
Esempio n. 14
0
        public void Dispose()
        {
            if (TokenSource != null)
            {
                if (!TokenSource.IsCancellationRequested)
                {
                    TokenSource.Cancel();
                }
                TokenSource.Dispose();
                TokenSource = null;
            }

            if (_SslStream != null)
            {
                try
                {
                    _SslStream.Close();
                }
                catch (Exception)
                {
                }
            }

            if (_NetworkStream != null)
            {
                try
                {
                    _NetworkStream.Close();
                }
                catch (Exception)
                {
                }
            }

            if (_TcpClient != null)
            {
                try
                {
                    _TcpClient.Close();
                    _TcpClient.Dispose();
                    _TcpClient = null;
                }
                catch (Exception)
                {
                }
            }
        }
Esempio n. 15
0
 public void DisposeReset()
 {
     try
     {
         if (Task != null)
         {
             Task.Dispose();
             Task = null;
         }
         if (TokenSource != null)
         {
             TokenSource.Dispose();
             TokenSource = new CancellationTokenSource();
         }
     }
     catch { }
 }
Esempio n. 16
0
        /// <summary>
        /// Tear down the object and dispose of resources.
        /// </summary>
        public void Dispose()
        {
            if (_SslStream != null)
            {
                _SslStream.Close();
                _SslStream.Dispose();
                _SslStream = null;
            }

            if (_NetworkStream != null)
            {
                _NetworkStream.Close();
                _NetworkStream.Dispose();
                _NetworkStream = null;
            }

            if (TokenSource != null)
            {
                if (!TokenSource.IsCancellationRequested)
                {
                    TokenSource.Cancel();
                }
                TokenSource.Dispose();
                TokenSource = null;
            }

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

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

            if (_TcpClient != null)
            {
                _TcpClient.Close();
                _TcpClient.Dispose();
                _TcpClient = null;
            }
        }
Esempio n. 17
0
        public override void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }

            try
            {
                Stop();
                Listener.Close();
                TokenSource?.Dispose();
            }
            finally
            {
                IsDisposed = true;
            }
        }
Esempio n. 18
0
        public void Dispose()
        {
            if (!IsDisposed)
            {
                IsDisposed = true;

                try
                {
                    TokenSource.Cancel();
                }
                catch { }
                TokenSource.Dispose();
                SemaphoreCount.Dispose();

                lock (Data)
                {
                    Data.Clear();
                }
            }
        }
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                    _destinationStream = null;
                    if (TokenSource != null)
                    {
                        TokenSource.Cancel();
                        TokenSource.Dispose();
                        TokenSource = null;
                    }
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
Esempio n. 20
0
        public void Reset()
        {
            IsActive = false;

            if (TokenSource != null)
            {
                if (!TokenSource.IsCancellationRequested)
                {
                    TokenSource.Cancel();
                    TokenSource.Dispose();
                }
            }

            if (NetworkStream != null)
            {
                NetworkStream.Close();
            }

            if (TcpClient != null)
            {
                TcpClient.Close();
                TcpClient.Dispose();
            }
        }
Esempio n. 21
0
        public async void btCopy_Click(object oSender, EventArgs oArgs)
        {
            try
            {
                TokenSource ??= new CancellationTokenSource();

                if (IsProcessing)
                {
                    TokenSource?.Cancel();
                    return;
                }

                await _currentControl.Run().ConfigureAwait(true);
            }
            catch (Exception oException)
            {
                MessageBox.Show(oException.ToString());
            }
            finally
            {
                ProgressBar.ResetText();
                TokenSource?.Dispose();
            }
        }
 public void Dispose()
 {
     Cancel(DelayAfterError);
     TokenSource?.Dispose();
 }
Esempio n. 23
0
        public override void Start()
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }
            if (IsListening || IsStarting || IsStopping)
            {
                return;
            }
            IsStarting = true;

            var exceptionWasThrown = false;

            try
            {
                // 1. Reset CancellationTokenSource
                TokenSource?.Dispose();
                TokenSource = new CancellationTokenSource();

                // 2. Execute BeforeStarting event handlers
                BeforeStarting?.Invoke(this);

                // 3. Optionally autoscan for routes
                if (Router.RoutingTable.Count == 0 && Options.EnableAutoScan)
                {
                    Router.Register(RouteScanner.Scan());
                }

                // 4. Configure and start the listener
                Listener.Start();

                // 5. Start the request handler thread
                RequestHandler.Start();

                // 6. Execute AfterStarting event handlers
                AfterStarting?.Invoke(this);
            }
            catch (HttpListenerException hl) when(hl.ErrorCode == 32)
            {
                /*
                 * When the port you are attempting to bind to is already in use
                 * by another application, the error can sometimes be unintuitive.
                 */

                exceptionWasThrown = true;

                var message   = $"One or more ports are already in use by another application.";
                var exception = new ArgumentException(message, hl);

                Logger.LogCritical(exception, message);
                throw exception;
            }
            catch (Exception e)
            {
                exceptionWasThrown = true;

                Logger.LogCritical(e, "An unexpected error occured when attempting to start the server");
                throw;
            }
            finally
            {
                if (exceptionWasThrown)
                {
                    Listener.Stop();
                    TokenSource.Cancel();
                }

                IsStarting = false;
            }
        }
Esempio n. 24
0
 public void Dispose()
 {
     //Dispose
     isDisposed = true;
     TokenSource.Dispose();
 }
Esempio n. 25
0
 public void Dispose()
 {
     TokenSource.Dispose();
 }
Esempio n. 26
0
 public void Dispose()
 {
     Stop();
     TokenSource?.Dispose();
 }
Esempio n. 27
0
 public void Dispose()
 {
     TokenSource?.Cancel();
     TokenSource?.Dispose();
     Responses?.CompleteAdding();
 }
Esempio n. 28
0
        /// <summary>
        /// アニメーションを開始する
        /// </summary>
        /// <param name="visible">ウィンドウの表示・非表示</param>
        private bool StartAnimation(bool visible)
        {
            if (TokenSource != null)
            {
                if (IsAnimation)
                {
                    TokenSource.Cancel();
                }
                TokenSource.Dispose();
                TokenSource = null;
            }
            TokenSource = new CancellationTokenSource();
            CancelToken = TokenSource.Token;

            if ((!visible && FormVisible) || (visible && !FormVisible))
            {
                GHFormDraw();

                FormVisible = visible;

                // 非表示遅延時間の更新
                HideTimer.Interval = animateInfo._DelayTime;
                IsAnimation        = true;
                StopwatchTotal     = 0;

                // スライドアニメーション
                if (animateInfo._Slide)
                {
                    RemainingDistanceOfSlide = 0;
                    if (GHManager.IsVertical)
                    {
                        Left = !visible ? GHFormShowPosition : GHFormHidePosition;
                    }
                    else
                    {
                        Top = !visible ? GHFormShowPosition : GHFormHidePosition;
                    }
                }
                else
                {
                    // スライドなしフェード
                    if (GHManager.IsVertical)
                    {
                        Left = GHFormHidePosition = GHFormShowPosition;
                    }
                    else
                    {
                        Top = GHFormHidePosition = GHFormShowPosition;
                    }
                }

                // フェードアニメーション
                if (animateInfo._Fade)
                {
                    animateInfo._Alpha = (byte)(!visible ? 255 : 0);
                }
                else
                {
                    // フェードなしスライド
                    if (animateInfo._Slide)
                    {
                        animateInfo._Alpha = 255;
                    }
                    else
                    {
                        animateInfo._Alpha = (byte)(!visible ? 0 : 255);
                    }
                }

                // アニメーション開始
                AnimationStopwatch.Restart();
                GHFormAnimation(CancelToken);

                // ランチャーを最前面
                GHManager.ItemList.BringToFront();
                GHManager.MysetList.BringToFront();
                GHManager.Launcher.BringToFront();

                return(true);
            }

            return(false);
        }