private readonly ICoreTask _task;
private bool _disposedValue = false;
- private static System.Timers.Timer sTimer;
-
/// <summary>
/// Initializes the CoreApplication class.
/// </summary>
protected virtual void OnLowMemory(LowMemoryEventArgs e)
{
LowMemory?.Invoke(this, e);
- double interval = new Random().Next(10 * 1000);
- if (interval <= 0)
- interval = 10 * 1000;
-
- sTimer = new System.Timers.Timer(interval);
- sTimer.Elapsed += OnTimedEvent;
- sTimer.AutoReset = false;
- sTimer.Enabled = true;
- }
-
- private static void OnTimedEvent(Object source, ElapsedEventArgs e)
- {
- System.GC.Collect();
+ if (e.LowMemoryStatus == LowMemoryStatus.SoftWarning || e.LowMemoryStatus == LowMemoryStatus.HardWarning)
+ {
+ System.GC.Collect();
+ }
}
/// <summary>
}
/// <summary>
- /// Dispatches an asynchronous message to the main loop of the CoreTask.
+ /// Dispatches an asynchronous message to a main loop of the CoreApplication.
/// </summary>
+ /// <remarks>
+ /// If an application uses UI thread App Model, the asynchronous message will be delivered to the UI thread.
+ /// If not, the asynchronous message will be delivered to the main thread.
+ /// </remarks>
/// <param name="runner">The runner callaback.</param>
/// <exception cref="ArgumentNullException">Thrown when the runner is null.</exception>
/// <since_tizen> 10 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
- public void Post(Action runner)
+ public static void Post(Action runner)
{
if (runner == null)
{
throw new ArgumentNullException(nameof(runner));
}
- GSourceManager.Post(runner);
+ GSourceManager.Post(runner, true);
}
/// <summary>
- /// Dispatches an asynchronous message to the main loop of the CoreTask.
+ /// Dispatches an asynchronous message to a main loop of the CoreApplication.
/// </summary>
+ /// <remarks>
+ /// If an application uses UI thread App Model, the asynchronous message will be delivered to the UI thread.
+ /// If not, the asynchronous message will be delivered to the main thread.
+ /// </remarks>
/// <typeparam name="T">The type of the result.</typeparam>
/// <param name="runner">The runner callback.</param>
/// <exception cref="ArgumentNullException">Thrown when the runner is null.</exception>
/// <returns>A task with the result.</returns>
/// <since_tizen> 10 </since_tizen>
[EditorBrowsable(EditorBrowsableState.Never)]
- public async Task<T> Post<T>(Func<T> runner)
+ public static async Task<T> Post<T>(Func<T> runner)
{
if (runner == null)
{
}
var task = new TaskCompletionSource<T>();
- GSourceManager.Post(() => { task.SetResult(runner()); });
+ GSourceManager.Post(() => { task.SetResult(runner()); }, true);
return await task.Task.ConfigureAwait(false);
}