Ejemplo n.º 1
0
        /// <summary>
        /// Dispatches a synchronous message to a Tizen main loop.
        /// </summary>
        /// <param name="d"><see cref="System.Threading.SendOrPostCallback"/>The SendOrPostCallback delegate to call.</param>
        /// <param name="state"><see cref="System.Object"/>The object passed to the delegate.</param>
        /// <remarks>
        /// The send method starts a synchronous request to send a message.</remarks>
        /// <since_tizen> 3 </since_tizen>
        public override void Send(SendOrPostCallback d, object state)
        {
            var       mre = new ManualResetEvent(false);
            Exception err = null;

            GSourceManager.Post(() =>
            {
                try
                {
                    d(state);
                }
                catch (Exception ex)
                {
                    err = ex;
                }
                finally
                {
                    mre.Set();
                }
            });
            mre.WaitOne();
            if (err != null)
            {
                throw err;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Dispatches an asynchronous message to a Tizen main loop.
 /// </summary>
 /// <param name="d"><see cref="System.Threading.SendOrPostCallback"/>The SendOrPostCallback delegate to call.</param>
 /// <param name="state"><see cref="System.Object"/>The object passed to the delegate.</param>
 /// <remarks>
 /// The post method starts an asynchronous request to post a message.</remarks>
 /// <since_tizen> 3 </since_tizen>
 public override void Post(SendOrPostCallback d, object state)
 {
     GSourceManager.Post(() =>
     {
         d(state);
     });
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 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>
        /// <since_tizen> 10 </since_tizen>
        public void Post(Action runner)
        {
            if (runner == null)
            {
                throw new ArgumentNullException(nameof(runner));
            }

            GSourceManager.Post(runner, true);
        }
Ejemplo n.º 4
0
        /// <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));
        }