diff --git a/DS4Windows/App.xaml.cs b/DS4Windows/App.xaml.cs index ea3dea1..c3a0e12 100644 --- a/DS4Windows/App.xaml.cs +++ b/DS4Windows/App.xaml.cs @@ -188,6 +188,7 @@ namespace DS4WinWPF { Dispatcher.Invoke(() => { + rootHub.PrepareAbort(); CleanShutdown(); }); } diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 2972ddd..8a0f832 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -688,6 +688,18 @@ namespace DS4Windows } } + public void PrepareAbort() + { + for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++) + { + DS4Device tempDevice = DS4Controllers[i]; + if (tempDevice != null) + { + tempDevice.PrepareAbort(); + } + } + } + public bool Stop(bool showlog = true) { if (running) diff --git a/DS4Windows/DS4Library/DS4Device.cs b/DS4Windows/DS4Library/DS4Device.cs index b38a1cc..ab79d21 100644 --- a/DS4Windows/DS4Library/DS4Device.cs +++ b/DS4Windows/DS4Library/DS4Device.cs @@ -608,9 +608,8 @@ namespace DS4Windows try { exitInputThread = true; - if (ds4Input.ThreadState.HasFlag(System.Threading.ThreadState.WaitSleepJoin)) - ds4Input.Interrupt(); - else + //ds4Input.Interrupt(); + if (!abortInputThread) ds4Input.Join(); } catch (Exception e) @@ -1582,5 +1581,11 @@ namespace DS4Windows { return !test.Equals(blankSerial); } + + private bool abortInputThread = false; + public void PrepareAbort() + { + abortInputThread = true; + } } }