/// <summary>
        /// Stops the TorrentManager
        /// </summary>
        public void Stop()
        {
            if (State == TorrentState.Error)
            {
                error = null;
                Mode  = new StoppedMode(this);
                return;
            }

            if (Mode is StoppingMode)
            {
                return;
            }

            ClientEngine.MainLoop.QueueWait(delegate
            {
                if (State != TorrentState.Stopped)
                {
#if !DISABLE_DHT
                    engine.DhtEngine.PeersFound -= DhtPeersFound;
#endif
                    Mode = new StoppingMode(this);
                }
            });
        }
        /// <summary>
        /// Stops the TorrentManager
        /// </summary>
        public async Task StopAsync()
        {
            await ClientEngine.MainLoop;

            if (State == TorrentState.Error)
            {
                Error = null;
                Mode  = new StoppedMode(this);
                return;
            }

            if (Mode is StoppingMode)
            {
                return;
            }

            if (State != TorrentState.Stopped)
            {
                Engine.DhtEngine.PeersFound -= DhtPeersFound;
                Mode = new StoppingMode(this);
            }
        }
        /// <summary>
        /// Stops the TorrentManager
        /// </summary>
        public async Task StopAsync()
        {
            await ClientEngine.MainLoop;

            if (State == TorrentState.Error)
            {
                Error = null;
                Mode  = new StoppedMode(this);
                return;
            }

            if (State != TorrentState.Stopped)
            {
                Engine.DhtEngine.PeersFound -= DhtPeersFound;
                var stoppingMode = new StoppingMode(this);
                Mode = stoppingMode;

                await stoppingMode.WaitForStoppingToComplete();

                Mode = new StoppedMode(this);
                Engine.Stop();
            }
        }
Exemple #4
0
        /// <summary>
        /// Stops the TorrentManager. The returned task completes as soon as the manager has fully stopped.
        /// </summary>
        public async Task StopAsync()
        {
            await ClientEngine.MainLoop;

            if (Mode is StoppingMode)
            {
                throw new TorrentException("The manager cannot be stopped while it is already in the Stopping state.");
            }

            if (State == TorrentState.Error)
            {
                Error = null;
                Mode  = new StoppedMode(this, Engine.DiskManager, Engine.ConnectionManager, Engine.Settings);
            }
            else if (State != TorrentState.Stopped)
            {
                var stoppingMode = new StoppingMode(this, Engine.DiskManager, Engine.ConnectionManager, Engine.Settings);
                Mode = stoppingMode;
                await stoppingMode.WaitForStoppingToComplete();

                Mode = new StoppedMode(this, Engine.DiskManager, Engine.ConnectionManager, Engine.Settings);
                Engine.Stop();
            }
        }