Skip to content

Commit

Permalink
Use periodic garbage collection
Browse files Browse the repository at this point in the history
Related to issue Ryochan7#866
  • Loading branch information
Ryochan7 committed Nov 1, 2019
1 parent 8c12fe7 commit 26f0b17
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion DS4Windows/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public struct COPYDATASTRUCT
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
Expand Down Expand Up @@ -192,14 +193,22 @@ static void Main(string[] args)

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();
while (controlThread.IsAlive)
Thread.SpinWait(500);
}

private static void GarbageTask(object state)
{
GC.Collect(0, GCCollectionMode.Forced, false);
}

private static void CreateTempWorkerThread()
{
testThread = new Thread(SingleAppComThread_DoWork);
Expand Down

0 comments on commit 26f0b17

Please sign in to comment.