/// <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(); } }
/// <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(); } }