From 31f1382245b60d8a16516e1e72d8677aaf88ab1a Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Sat, 3 Jun 2017 15:35:13 -0700 Subject: [PATCH] Change when sleep is run for device removal --- DS4Windows/DS4Control/ControlService.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index a771ef2..3716f33 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Media; using System.Threading.Tasks; +using System.Diagnostics; using static DS4Windows.Global; namespace DS4Windows @@ -614,7 +615,17 @@ namespace DS4Windows LogDebug(removed); Log.LogToTray(removed); - System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME); + /*Stopwatch sw = new Stopwatch(); + sw.Start(); + while (sw.ElapsedMilliseconds < XINPUT_UNPLUG_SETTLE_TIME) + { + // Use SpinWait to keep control of current thread. Using Sleep could potentially + // cause other events to get run out of order + System.Threading.Thread.SpinWait(500); + } + sw.Stop(); + */ + device.IsRemoved = true; device.Synced = false; DS4Controllers[ind] = null; @@ -622,6 +633,7 @@ namespace DS4Windows lag[ind] = false; inWarnMonitor[ind] = false; useDInputOnly[ind] = false; + System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME); OnControllerRemoved(this, ind); } }