Exemple #1
0
        /// <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
        }