[Tizen.Applications.Common] Add a timer for handling GC collection (#710)
authorpjh9216 <jh9216.park@samsung.com>
Wed, 13 Feb 2019 11:07:40 +0000 (20:07 +0900)
committerGitHub <noreply@github.com>
Wed, 13 Feb 2019 11:07:40 +0000 (20:07 +0900)
* Add a timer for handling GC collection

- Once apps receive low memory events, GC collection will happen at the
  same time.
- This patch is for distribution of GC collection event.

Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
* Use overloaded method for Random.next

Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs

index b2c48c4..52ffff9 100755 (executable)
@@ -17,6 +17,7 @@
 using System;
 using System.Globalization;
 using System.Text;
+using System.Timers;
 using Tizen.Applications.CoreBackend;
 
 namespace Tizen.Applications
@@ -30,6 +31,8 @@ namespace Tizen.Applications
         private readonly ICoreBackend _backend;
         private bool _disposedValue = false;
 
+        private static Timer sTimer;
+
         /// <summary>
         /// Initializes the CoreApplication class.
         /// </summary>
@@ -171,6 +174,14 @@ namespace Tizen.Applications
         protected virtual void OnLowMemory(LowMemoryEventArgs e)
         {
             LowMemory?.Invoke(this, e);
+            sTimer = new Timer(new Random().Next(10 * 1000));
+            sTimer.Elapsed += OnTimedEvent;
+            sTimer.AutoReset = false;
+            sTimer.Enabled = true;
+        }
+
+        private static void OnTimedEvent(Object source, ElapsedEventArgs e)
+        {
             System.GC.Collect();
         }