From 22babe9ded603c14cfdd28c2f8827031c80bd46d Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Tue, 1 Aug 2017 02:42:59 -0500 Subject: [PATCH] Trim hotplug launching routine to speed up main thread --- DS4Windows/DS4Forms/DS4Form.cs | 35 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/DS4Windows/DS4Forms/DS4Form.cs b/DS4Windows/DS4Forms/DS4Form.cs index 3d5f323..3e77bcd 100644 --- a/DS4Windows/DS4Forms/DS4Form.cs +++ b/DS4Windows/DS4Forms/DS4Form.cs @@ -1040,37 +1040,26 @@ namespace DS4Windows protected async void InnerHotplug2() { - //await System.Threading.Tasks.Task.Delay(50); - - /*if (inHotPlug) + inHotPlug = true; + System.Threading.SynchronizationContext uiContext = + System.Threading.SynchronizationContext.Current; + bool loopHotplug = false; + lock (hotplugCounterLock) { - await System.Threading.Tasks.Task.Run(() => { while (inHotPlug) { System.Threading.Thread.Sleep(50); } }); + loopHotplug = hotplugCounter > 0; } - */ - //lock (this) + while (loopHotplug == true) { - inHotPlug = true; - System.Threading.SynchronizationContext uiContext = System.Threading.SynchronizationContext.Current; - int tempCount = 0; + await System.Threading.Tasks.Task.Run(() => { Program.rootHub.HotPlug(uiContext); }); lock (hotplugCounterLock) { - tempCount = hotplugCounter; + hotplugCounter--; + loopHotplug = hotplugCounter > 0; } - - while (tempCount > 0) - { - await System.Threading.Tasks.Task.Run(() => { Program.rootHub.HotPlug(uiContext); }); - lock (hotplugCounterLock) - { - hotplugCounter--; - tempCount = hotplugCounter; - } - } - - //Program.rootHub.HotPlug(); - inHotPlug = false; } + + inHotPlug = false; } protected void BatteryStatusUpdate(object sender, BatteryReportArgs args)