Tweak temp thread creation

This commit is contained in:
Travis Nickles 2017-09-05 21:28:54 -05:00
parent c6d7507a01
commit e847fd6458
2 changed files with 26 additions and 4 deletions

View File

@ -27,6 +27,7 @@ namespace DS4Windows
List<DS4Controls> dcs = new List<DS4Controls>(); List<DS4Controls> dcs = new List<DS4Controls>();
bool[] held = new bool[DS4_CONTROLLER_COUNT]; bool[] held = new bool[DS4_CONTROLLER_COUNT];
int[] oldmouse = new int[DS4_CONTROLLER_COUNT] { -1, -1, -1, -1 }; int[] oldmouse = new int[DS4_CONTROLLER_COUNT] { -1, -1, -1, -1 };
Thread tempThread;
//SoundPlayer sp = new SoundPlayer(); //SoundPlayer sp = new SoundPlayer();
private class X360Data private class X360Data
@ -41,10 +42,19 @@ namespace DS4Windows
{ {
//sp.Stream = Properties.Resources.EE; //sp.Stream = Properties.Resources.EE;
// Cause thread affinity to not be tied to main GUI thread // 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(); x360task.Start();
while (!x360task.IsCompleted) while (!x360task.IsCompleted)
Thread.SpinWait(500); 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(); AddtoDS4List();

View File

@ -23,6 +23,7 @@ namespace DS4Windows
private static EventWaitHandle threadComEvent = null; private static EventWaitHandle threadComEvent = null;
private static bool exitComThread = false; private static bool exitComThread = false;
public static ControlService rootHub; public static ControlService rootHub;
private static Thread testThread;
/// <summary> /// <summary>
/// The main entry point for the application. /// The main entry point for the application.
@ -95,7 +96,10 @@ namespace DS4Windows
// Create the Event handle // Create the Event handle
threadComEvent = new EventWaitHandle(false, EventResetMode.ManualReset, SingleAppComEventName); 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)) //if (mutex.WaitOne(TimeSpan.Zero, true))
//{ //{
@ -113,7 +117,15 @@ namespace DS4Windows
threadComEvent.Close(); 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 = new BackgroundWorker();
singleAppComThread.DoWork += new DoWorkEventHandler(singleAppComThread_DoWork); singleAppComThread.DoWork += new DoWorkEventHandler(singleAppComThread_DoWork);
@ -122,9 +134,9 @@ namespace DS4Windows
static private void singleAppComThread_DoWork(object sender, DoWorkEventArgs e) static private void singleAppComThread_DoWork(object sender, DoWorkEventArgs e)
{ {
Thread.CurrentThread.Priority = ThreadPriority.Lowest;
BackgroundWorker worker = sender as BackgroundWorker; BackgroundWorker worker = sender as BackgroundWorker;
WaitHandle[] waitHandles = new WaitHandle[] { threadComEvent }; WaitHandle[] waitHandles = new WaitHandle[] { threadComEvent };
Thread.CurrentThread.Priority = ThreadPriority.Lowest;
while (!exitComThread) while (!exitComThread)
{ {