*/
using System;
-using System.Collections.Generic;
+using System.Collections.Concurrent;
namespace ElmSharp
{
/// <summary>
- /// EcoreMainloop is a helper class, it provide functions relative Ecore's main loop.
+ /// EcoreMainloop is a helper class, which provides the functions relative to Ecore's main loop.
/// </summary>
+ /// <since_tizen> preview </since_tizen>
public static class EcoreMainloop
{
- static readonly Dictionary<int, Func<bool>> _taskMap = new Dictionary<int, Func<bool>>();
+
+ static readonly ConcurrentDictionary<int, Func<bool>> _taskMap = new ConcurrentDictionary<int, Func<bool>>();
static readonly Object _taskLock = new Object();
static int _newTaskId = 0;
/// <summary>
/// Checks if you are calling this function from the main thread.
/// </summary>
- /// <remarks>True is the calling function is the same thread, false otherwise.</remarks>
+ /// <remarks>True if the calling function is the same thread, false otherwise.</remarks>
+ /// <since_tizen> preview </since_tizen>
public static bool IsMainThread => Interop.Eina.eina_main_loop_is();
/// <summary>
/// Runs the application main loop.
/// </summary>
+ /// <since_tizen> preview </since_tizen>
public static void Begin()
{
Interop.Ecore.ecore_main_loop_begin();
}
/// <summary>
- /// Quits the main loop once all the events currently on the queue have been processed.
+ /// Quits the main loop, once all the events currently on the queue have been processed.
/// </summary>
+ /// <since_tizen> preview </since_tizen>
public static void Quit()
{
Interop.Ecore.ecore_main_loop_quit();
/// <summary>
/// Adds an idler handler.
/// </summary>
- /// <param name="task">The action to call when idling</param>
+ /// <param name="task">The action to call when idle.</param>
+ /// <since_tizen> preview </since_tizen>
public static void Post(Action task)
{
int id = RegistHandler(() => { task(); return false; });
}
/// <summary>
- /// Calls callback asynchronously in the main loop.
+ /// Calls the callback asynchronously in the main loop.
/// </summary>
- /// <param name="task">The action wanted to be called</param>
+ /// <param name="task">The action wanted to be called.</param>
+ /// <since_tizen> preview </since_tizen>
public static void PostAndWakeUp(Action task)
{
int id = RegistHandler(() => { task(); return false; });
}
/// <summary>
- /// Calls callback synchronously in the main loop.
+ /// Calls the callback synchronously in the main loop.
/// </summary>
- /// <param name="task">The action wanted to be called</param>
+ /// <param name="task">The action wanted to be called.</param>
+ /// <since_tizen> preview </since_tizen>
public static void Send(Action task)
{
int id = RegistHandler(() => { task(); return false; });
/// </summary>
/// <param name="interval">The interval in seconds.</param>
/// <param name="handler">The given function.</param>
- /// <returns>A timer object handler on success, NULL on failure.</returns>
+ /// <returns>A timer object handler on success, or null on failure.</returns>
+ /// <since_tizen> preview </since_tizen>
public static IntPtr AddTimer(double interval, Func<bool> handler)
{
int id = RegistHandler(handler);
/// Removes the specified timer from the timer list.
/// </summary>
/// <param name="id">The specified timer handler</param>
+ /// <since_tizen> preview </since_tizen>
public static void RemoveTimer(IntPtr id)
{
int taskId = (int)Interop.Ecore.ecore_timer_del(id);
- _taskMap.Remove(taskId);
+ Func<bool> unused;
+ _taskMap.TryRemove(taskId, out unused);
}
static int RegistHandler(Func<bool> task)
bool result = false;
if (userAction != null)
+ {
result = userAction();
+ }
- if (result == false)
- _taskMap.Remove(task_id);
-
+ if (!result)
+ {
+ _taskMap.TryRemove(task_id, out userAction);
+ }
return result;
}
return false;