From 26f0b1783e0a33892b58a890c42742a76c922072 Mon Sep 17 00:00:00 2001 From: Travis Nickles Date: Thu, 31 Oct 2019 21:50:19 -0500 Subject: [PATCH] Use periodic garbage collection Related to issue #866 --- DS4Windows/Program.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/DS4Windows/Program.cs b/DS4Windows/Program.cs index 81dabe2..8f01d43 100644 --- a/DS4Windows/Program.cs +++ b/DS4Windows/Program.cs @@ -39,6 +39,7 @@ namespace DS4Windows public static ControlService rootHub; private static Thread testThread; private static Thread controlThread; + private static System.Threading.Timer collectTimer; private static Form ds4form; 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() { - 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.IsBackground = true; controlThread.Start(); @@ -200,6 +204,11 @@ namespace DS4Windows Thread.SpinWait(500); } + private static void GarbageTask(object state) + { + GC.Collect(0, GCCollectionMode.Forced, false); + } + private static void CreateTempWorkerThread() { testThread = new Thread(SingleAppComThread_DoWork);