Make sure uiContext is available for invoking events

This commit is contained in:
Travis Nickles 2017-08-25 16:38:17 -05:00
parent 33966389a4
commit ea858feafa

View File

@ -14,6 +14,7 @@ using System.Text;
using System.Globalization; using System.Globalization;
using Microsoft.Win32.TaskScheduler; using Microsoft.Win32.TaskScheduler;
using System.Security.Principal; using System.Security.Principal;
using System.Threading;
using static DS4Windows.Global; using static DS4Windows.Global;
namespace DS4Windows namespace DS4Windows
@ -145,7 +146,7 @@ namespace DS4Windows
new SaveWhere(false).ShowDialog(); new SaveWhere(false).ShowDialog();
} }
System.Threading.Thread AppCollectionThread = new System.Threading.Thread(() => CheckDrivers()); Thread AppCollectionThread = new Thread(() => CheckDrivers());
AppCollectionThread.IsBackground = true; AppCollectionThread.IsBackground = true;
AppCollectionThread.Start(); AppCollectionThread.Start();
@ -368,7 +369,7 @@ namespace DS4Windows
if (File.Exists(exepath + "\\Updater.exe")) if (File.Exists(exepath + "\\Updater.exe"))
{ {
System.Threading.Thread.Sleep(2000); Thread.Sleep(2000);
File.Delete(exepath + "\\Updater.exe"); File.Delete(exepath + "\\Updater.exe");
} }
@ -491,7 +492,7 @@ namespace DS4Windows
Process[] processes = Process.GetProcessesByName("DS4Updater"); Process[] processes = Process.GetProcessesByName("DS4Updater");
while (processes.Length > 0) while (processes.Length > 0)
{ {
System.Threading.Thread.Sleep(500); Thread.Sleep(500);
} }
File.Delete(exepath + "\\DS4Updater.exe"); File.Delete(exepath + "\\DS4Updater.exe");
@ -1000,10 +1001,11 @@ namespace DS4Windows
hotplugCounter++; hotplugCounter++;
} }
var uiContext = SynchronizationContext.Current;
if (!inHotPlug) if (!inHotPlug)
{ {
inHotPlug = true; inHotPlug = true;
System.Threading.Tasks.Task.Run(() => { InnerHotplug2(); }); System.Threading.Tasks.Task.Run(() => { InnerHotplug2(uiContext); });
} }
} }
} }
@ -1018,11 +1020,10 @@ namespace DS4Windows
catch { } catch { }
} }
protected void InnerHotplug2() private void InnerHotplug2(SynchronizationContext uiContext)
{ {
inHotPlug = true; inHotPlug = true;
System.Threading.SynchronizationContext uiContext =
System.Threading.SynchronizationContext.Current;
bool loopHotplug = false; bool loopHotplug = false;
lock (hotplugCounterLock) lock (hotplugCounterLock)
{ {
@ -1032,7 +1033,7 @@ namespace DS4Windows
while (loopHotplug == true) while (loopHotplug == true)
{ {
Program.rootHub.HotPlug(uiContext); Program.rootHub.HotPlug(uiContext);
//System.Threading.Tasks.Task.Run(() => { Program.rootHub.HotPlug(uiContext); }); //Tasks.Task.Run(() => { Program.rootHub.HotPlug(uiContext); });
lock (hotplugCounterLock) lock (hotplugCounterLock)
{ {
hotplugCounter--; hotplugCounter--;