diff --git a/DS4Windows/DS4Control/ControlSerivce.cs b/DS4Windows/DS4Control/ControlSerivce.cs index ad3cc70..c6cd1da 100644 --- a/DS4Windows/DS4Control/ControlSerivce.cs +++ b/DS4Windows/DS4Control/ControlSerivce.cs @@ -221,6 +221,7 @@ namespace DS4Windows DS4LightBar.forcedFlash[i] = 0; DS4LightBar.defaultLight = true; DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i], ExposedState[i], touchPad[i]); + DS4Controllers[i].IsRemoved = true; System.Threading.Thread.Sleep(50); } @@ -229,6 +230,8 @@ namespace DS4Windows anyUnplugged = true; DS4Controllers[i] = null; touchPad[i] = null; + lag[i] = false; + inWarnMonitor[i] = false; } } diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index de6c3af..09b4f2a 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -161,6 +161,7 @@ namespace DS4Windows } private bool exitOutputThread = false; + private bool exitInputThread = false; private object exitLocker = new object(); public event EventHandler Report = null; public event EventHandler Removal = null; @@ -421,7 +422,8 @@ namespace DS4Windows { try { - ds4Input.Abort(); + exitInputThread = true; + //ds4Input.Abort(); ds4Input.Join(); } catch (Exception e) @@ -540,7 +542,7 @@ namespace DS4Windows long oldtime = 0; Stopwatch sw = new Stopwatch(); sw.Start(); - while (true) + while (!exitInputThread) { string currerror = string.Empty; long curtime = sw.ElapsedMilliseconds; @@ -1053,6 +1055,11 @@ namespace DS4Windows return Mac; } + public void runRemoval() + { + Removal?.Invoke(this, EventArgs.Empty); + } + public void removeReportHandlers() { this.Report = null; diff --git a/DS4Windows/DS4Library/DS4Devices.cs b/DS4Windows/DS4Library/DS4Devices.cs index 2a51513..33c8f86 100644 --- a/DS4Windows/DS4Library/DS4Devices.cs +++ b/DS4Windows/DS4Library/DS4Devices.cs @@ -146,6 +146,7 @@ namespace DS4Windows { DS4Device device = devices.ElementAt(i); device.StopUpdate(); + //device.runRemoval(); device.HidDevice.CloseDevice(); } @@ -216,8 +217,6 @@ namespace DS4Windows throw new Exception("Error enabling device, error code = " + Marshal.GetLastWin32Error()); } - System.Threading.Thread.Sleep(50); - NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet); } }