public async static void Invoke(Action action, Windows.UI.Core.CoreDispatcherPriority Priority = Windows.UI.Core.CoreDispatcherPriority.Normal)
 {
     await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
         Priority, () =>
         {
             action();
         });
 }
Exemplo n.º 2
0
        public void Invoke(Action action, Windows.UI.Core.CoreDispatcherPriority Priority = Windows.UI.Core.CoreDispatcherPriority.Normal)
        {
            var reslut = CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Priority, () => { action(); });

            while (reslut.Status != AsyncStatus.Completed)
            {
                //
            }
            return;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the DelayInvoker class.
        /// </summary>
        /// <param name="action">The action to execute with delay. Null is allowed.</param>
        /// <param name="delayTime">Time to wait before executing the action.</param>
        /// <param name="delegatePriority">The dispatcher priority to use for methods and properties of this class if the caller is not in the thread for dispatcher.</param>
        public DelayInvoker(Action action, TimeSpan delayTime, TheDispatcherPriority delegatePriority)
        {
            _action           = action;
            _delegatePriority = delegatePriority;

            // Creates a timer.
            _dispatcherTimer          = new TheDispatcherTimer();
            _dispatcherTimer.Interval = delayTime;
            _dispatcherTimer.Tick    += DispatcherTimer_Tick;
        }
Exemplo n.º 4
0
 public static async Task RunOnUIThreadAsync(Windows.UI.Core.CoreDispatcherPriority priority, Action action)
 {
     try
     {
         await returnDispatcher().RunAsync(priority, () =>
         {
             action();
         });
     }
     catch (Exception ex)
     {
         var noawait = ExceptionHandler.HandleException(ex, false);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the DelayInvoker class.
        /// </summary>
        /// <param name="dispatcher">The Dispatcher to execute the action.</param>
        /// <param name="action">The action to execute with delay. Null is allowed.</param>
        /// <param name="delayTime">Time to wait before executing the action.</param>
        /// <param name="dispatcherPriority">The priority at which execute the action.</param>
        /// <param name="delegatePriority">The dispatcher priority to use for methods and properties of this class if the caller is not in the thread for dispatcher.</param>
        public DelayInvoker(TheDispatcher dispatcher, Action action, TimeSpan delayTime, TheDispatcherPriority dispatcherPriority, TheDispatcherPriority delegatePriority)
        {
            if (dispatcher == null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }

            _dispatcher       = dispatcher;
            _action           = action;
            _delegatePriority = delegatePriority;

            // Creates a timer.
            _dispatcherTimer          = new TheDispatcherTimer(dispatcherPriority, dispatcher);
            _dispatcherTimer.Interval = delayTime;
            _dispatcherTimer.Tick    += DispatcherTimer_Tick;
        }
Exemplo n.º 6
0
 public static async void Invoke(Action action, Windows.UI.Core.CoreDispatcherPriority Priority = Windows.UI.Core.CoreDispatcherPriority.Normal)
 {
     try
     {
         await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Priority,
                                                                                                     () => { action(); });
     }
     catch (Exception)
     {
         /*
          * Invoke((async () =>
          * {
          *  await new ContentDialog
          *  {
          *      Title = "发生错误",
          *      Content = "Error: " + e.Message + "\r\n" + e.StackTrace,
          *      CloseButtonText = "关闭",
          *      DefaultButton = ContentDialogButton.Close
          *  }.ShowAsync();
          * }));
          */
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the DelayInvoker class.
 /// </summary>
 /// <remarks>
 /// This constructor uses the dispatcher returned by the Dispatcher.CurrentDispatcher.
 /// </remarks>
 /// <param name="action">The action to execute with delay. Null is allowed.</param>
 /// <param name="delayTime">Time to wait before executing the action.</param>
 /// <param name="dispatcherPriority">The priority at which execute the action.</param>
 public DelayInvoker(Action action, TimeSpan delayTime, TheDispatcherPriority dispatcherPriority)
     : this(TheDispatcher.CurrentDispatcher, action, delayTime, dispatcherPriority)
 {
 }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the DelayInvoker class.
 /// </summary>
 /// <param name="dispatcher">The Dispatcher to execute the action.</param>
 /// <param name="action">The action to execute with delay. Null is allowed.</param>
 /// <param name="delayTime">Time to wait before executing the action.</param>
 /// <param name="dispatcherPriority">The priority at which execute the action.</param>
 public DelayInvoker(TheDispatcher dispatcher, Action action, TimeSpan delayTime, TheDispatcherPriority dispatcherPriority)
     : this(dispatcher, action, delayTime, dispatcherPriority, DefaultDelegatePriority)
 {
 }
Exemplo n.º 9
0
 private void Invoke(Action action, Windows.UI.Core.CoreDispatcherPriority Priority = Windows.UI.Core.CoreDispatcherPriority.Normal)
 {
     var task = Task.Run(new Action(async delegate { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Priority, () => { action(); }); }));
 }