Use periodic garbage collection

Related to issue #866
This commit is contained in:
Travis Nickles 2019-10-31 21:50:19 -05:00
parent 8c12fe742c
commit 26f0b1783e

View File

@ -39,6 +39,7 @@ namespace DS4Windows
public static ControlService rootHub; public static ControlService rootHub;
private static Thread testThread; private static Thread testThread;
private static Thread controlThread; private static Thread controlThread;
private static System.Threading.Timer collectTimer;
private static Form ds4form; private static Form ds4form;
private static MemoryMappedFile ipcClassNameMMF = null; // MemoryMappedFile for inter-process communication used to hold className of DS4Form window private static MemoryMappedFile ipcClassNameMMF = null; // MemoryMappedFile for inter-process communication used to hold className of DS4Form window
@ -192,7 +193,10 @@ namespace DS4Windows
private static void createControlService() private static void createControlService()
{ {
controlThread = new Thread(() => { rootHub = new ControlService(); }); controlThread = new Thread(() => {
rootHub = new ControlService();
collectTimer = new System.Threading.Timer(GarbageTask, null, 30000, 30000);
});
controlThread.Priority = ThreadPriority.Normal; controlThread.Priority = ThreadPriority.Normal;
controlThread.IsBackground = true; controlThread.IsBackground = true;
controlThread.Start(); controlThread.Start();
@ -200,6 +204,11 @@ namespace DS4Windows
Thread.SpinWait(500); Thread.SpinWait(500);
} }
private static void GarbageTask(object state)
{
GC.Collect(0, GCCollectionMode.Forced, false);
}
private static void CreateTempWorkerThread() private static void CreateTempWorkerThread()
{ {
testThread = new Thread(SingleAppComThread_DoWork); testThread = new Thread(SingleAppComThread_DoWork);