using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
+using System.Threading.Tasks;
using System.Timers;
using Tizen.Applications.CoreBackend;
}
/// <summary>
+ /// Dispatches an asynchronous message to the main loop of the CoreTask.
+ /// </summary>
+ /// <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)
+ {
+ if (runner == null)
+ {
+ throw new ArgumentNullException(nameof(runner));
+ }
+
+ var task = new TaskCompletionSource<T>();
+ GSourceManager.Post(() => { task.SetResult(runner()); });
+ return await task.Task.ConfigureAwait(false);
+ }
+
+ /// <summary>
/// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
/// </summary>
/// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
*/
using System;
-using System.Collections.Concurrent;
using System.ComponentModel;
-using System.Threading;
-using static Tizen.Applications.TizenSynchronizationContext;
+using System.Threading.Tasks;
namespace Tizen.Applications
{
/// Dispatches an asynchronous message to the main loop of the CoreApplication.
/// </summary>
/// <param name="runner">The runner callback.</param>
- /// /// <exception cref="ArgumentNullException">Thrown when the runner is null.</exception>
+ /// <exception cref="ArgumentNullException">Thrown when the runner is null.</exception>
/// <since_tizen> 10 </since_tizen>
public void Post(Action runner)
{
GSourceManager.Post(runner, true);
}
+
+ /// <summary>
+ /// Dispatches an asynchronous message to the main loop of the CoreApplication.
+ /// </summary>
+ /// <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>
+
+ public async Task<T> Post<T>(Func<T> runner)
+ {
+ if (runner == null)
+ {
+ throw new ArgumentNullException(nameof(runner));
+ }
+
+ var task = new TaskCompletionSource<T>();
+ GSourceManager.Post(() => { task.SetResult(runner()); }, true);
+ return await task.Task.ConfigureAwait(false);
+ }
}
}