/// <summary> /// Executes the specified delegate asynchronously with the specified arguments on the thread that the Dispatcher was created on. /// </summary> /// <param name="action">The action.</param> /// <param name="onlyBeginInvokeWhenNoAccess">If set to <c>true</c>, the action will be executed directly if possible. Otherwise, /// <c>Dispatcher.BeginInvoke</c> will be used.</param> public virtual void BeginInvoke(Action action, bool onlyBeginInvokeWhenNoAccess = true) { Argument.IsNotNull("action", action); #if XAMARIN_FORMS var synchronizationContext = SynchronizationContext.Current; if (synchronizationContext != null) { synchronizationContext.Post(state => action(), null); } else { action(); } #elif ANDROID _handler.Post(action); #elif IOS DispatchQueue.MainQueue.DispatchAsync(() => action()); #else var dispatcher = CurrentDispatcher; DispatcherExtensions.BeginInvoke(dispatcher, action, onlyBeginInvokeWhenNoAccess); #endif }
/// <summary> /// Executes the specified delegate asynchronously with the specified arguments on the thread that the Dispatcher was created on. /// </summary> /// <param name="method">The method.</param> /// <param name="args">The arguments to pass into the method.</param> /// <returns>The task representing the action.</returns> public virtual Task InvokeAsync(Delegate method, params object[] args) { var dispatcher = CurrentDispatcher; return(DispatcherExtensions.InvokeAsync(dispatcher, method, args)); }
/// <summary> /// Executes the specified asynchronous operation on the thread that the Dispatcher was created on with the ability to return value with supporting of CancellationToken /// </summary> /// <typeparam name="T">The type of the result of the asynchronous operation</typeparam> /// <param name="funcAsync">The asynchronous operation which returns a value and supports cancelling</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The task representing the asynchronous operation with the returning value</returns> public virtual Task <T> InvokeTaskAsync <T>(Func <CancellationToken, Task <T> > funcAsync, CancellationToken cancellationToken) { var dispatcher = CurrentDispatcher; return(DispatcherExtensions.InvokeAsync(dispatcher, funcAsync, cancellationToken)); }
/// <summary> /// Executes the specified asynchronous operation on the thread that the Dispatcher was created on with the ability to return value. /// </summary> /// <typeparam name="T">The type of the result of the asynchronous operation</typeparam> /// <param name="funcAsync">The asynchronous operation which returns a value</param> /// <returns>The task representing the asynchronous operation with the returning value</returns> public virtual Task <T> InvokeTaskAsync <T>(Func <Task <T> > funcAsync) { var dispatcher = CurrentDispatcher; return(DispatcherExtensions.InvokeAsync(dispatcher, funcAsync)); }
/// <summary> /// Executes the specified asynchronous operation on the thread that the Dispatcher was created on /// </summary> /// <param name="actionAsync">The asynchronous operation without returning a value</param> /// <returns>The task representing the asynchronous operation</returns> public virtual Task InvokeTaskAsync(Func <Task> actionAsync) { var dispatcher = CurrentDispatcher; return(DispatcherExtensions.InvokeAsync(dispatcher, actionAsync)); }
/// <summary> /// Executes the specified asynchronous operation on the thread that the Dispatcher was created on with supporting of CancellationToken /// </summary> /// <param name="actionAsync">The asynchronous operation without returning a value</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The task representing the asynchronous operation</returns> public Task InvokeTaskAsync(Func <CancellationToken, Task> actionAsync, CancellationToken cancellationToken) { var dispatcher = CurrentDispatcher; return(DispatcherExtensions.InvokeAsync(dispatcher, actionAsync, cancellationToken)); }