From e847fd64582bb88766fde242288263e7fcf97820 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Tue, 5 Sep 2017 21:28:54 -0500 Subject: [PATCH] Tweak temp thread creation --- DS4Windows/DS4Control/ControlService.cs | 12 +++++++++++- DS4Windows/Program.cs | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs index 03330b3..54a9328 100644 --- a/DS4Windows/DS4Control/ControlService.cs +++ b/DS4Windows/DS4Control/ControlService.cs @@ -27,6 +27,7 @@ namespace DS4Windows List dcs = new List(); bool[] held = new bool[DS4_CONTROLLER_COUNT]; int[] oldmouse = new int[DS4_CONTROLLER_COUNT] { -1, -1, -1, -1 }; + Thread tempThread; //SoundPlayer sp = new SoundPlayer(); private class X360Data @@ -41,10 +42,19 @@ namespace DS4Windows { //sp.Stream = Properties.Resources.EE; // Cause thread affinity to not be tied to main GUI thread - Task x360task = new Task(() => { Thread.CurrentThread.Priority = ThreadPriority.AboveNormal; x360Bus = new X360Device(); }); + /*Task x360task = new Task(() => { Thread.CurrentThread.Priority = ThreadPriority.AboveNormal; x360Bus = new X360Device(); }); x360task.Start(); while (!x360task.IsCompleted) Thread.SpinWait(500); + */ + tempThread = new Thread(() => { x360Bus = new X360Device(); }); + tempThread.Priority = ThreadPriority.AboveNormal; + tempThread.IsBackground = true; + tempThread.Start(); + while (tempThread.IsAlive) + { + Thread.SpinWait(500); + } AddtoDS4List(); diff --git a/DS4Windows/Program.cs b/DS4Windows/Program.cs index dde7caf..d9b0928 100644 --- a/DS4Windows/Program.cs +++ b/DS4Windows/Program.cs @@ -23,6 +23,7 @@ namespace DS4Windows private static EventWaitHandle threadComEvent = null; private static bool exitComThread = false; public static ControlService rootHub; + private static Thread testThread; /// /// The main entry point for the application. @@ -95,7 +96,10 @@ namespace DS4Windows // Create the Event handle threadComEvent = new EventWaitHandle(false, EventResetMode.ManualReset, SingleAppComEventName); - System.Threading.Tasks.Task.Run(() => { Thread.CurrentThread.Priority = ThreadPriority.Lowest; CreateInterAppComThread(); }).Wait(); + //System.Threading.Tasks.Task.Run(() => CreateTempWorkerThread()); + //CreateInterAppComThread(); + CreateTempWorkerThread(); + //System.Threading.Tasks.Task.Run(() => { Thread.CurrentThread.Priority = ThreadPriority.Lowest; CreateInterAppComThread(); Thread.CurrentThread.Priority = ThreadPriority.Lowest; }).Wait(); //if (mutex.WaitOne(TimeSpan.Zero, true)) //{ @@ -113,7 +117,15 @@ namespace DS4Windows threadComEvent.Close(); } - static private void CreateInterAppComThread() + private static void CreateTempWorkerThread() + { + testThread = new Thread(CreateInterAppComThread); + testThread.Priority = ThreadPriority.Lowest; + testThread.IsBackground = true; + testThread.Start(); + } + + private static void CreateInterAppComThread() { singleAppComThread = new BackgroundWorker(); singleAppComThread.DoWork += new DoWorkEventHandler(singleAppComThread_DoWork); @@ -122,9 +134,9 @@ namespace DS4Windows static private void singleAppComThread_DoWork(object sender, DoWorkEventArgs e) { + Thread.CurrentThread.Priority = ThreadPriority.Lowest; BackgroundWorker worker = sender as BackgroundWorker; WaitHandle[] waitHandles = new WaitHandle[] { threadComEvent }; - Thread.CurrentThread.Priority = ThreadPriority.Lowest; while (!exitComThread) {