public bool Stop(bool showlog = true) { if (running) { running = false; runHotPlug = false; if (showlog) { LogDebug(Properties.Resources.StoppingX360); } bool anyUnplugged = false; for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++) { DS4Device tempDevice = DS4Controllers[i]; if (tempDevice != null) { if (DCBTatStop && !tempDevice.isCharging()) { if (tempDevice.getConnectionType() == ConnectionType.BT) { tempDevice.StopUpdate(); tempDevice.DisconnectBT(true); } else if (tempDevice.getConnectionType() == ConnectionType.SONYWA) { tempDevice.StopUpdate(); tempDevice.DisconnectDongle(true); } } else { DS4LightBar.forcelight[i] = false; DS4LightBar.forcedFlash[i] = 0; DS4LightBar.defaultLight = true; DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i], ExposedState[i], touchPad[i]); tempDevice.IsRemoved = true; Thread.Sleep(50); } CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change. x360Bus.Unplug(i); useDInputOnly[i] = true; anyUnplugged = true; DS4Controllers[i] = null; touchPad[i] = null; lag[i] = false; inWarnMonitor[i] = false; } } if (anyUnplugged) { Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME); } x360Bus.UnplugAll(); x360Bus.Stop(); if (showlog) { LogDebug(Properties.Resources.StoppingDS4); } DS4Devices.stopControllers(); if (_udpServer != null) { _udpServer.Stop(); } if (showlog) { LogDebug(Properties.Resources.StoppedDS4Windows); } } runHotPlug = false; return(true); }