예제 #1
0
 public void InvokeOnUIThread(Action action)
 {
     if (CurrentDispatcher.CheckAccess())
     {
         action();
     }
     else
     {
         CurrentDispatcher.Invoke(action);
     }
 }
예제 #2
0
        public Task InvokeOnUIThreadAsync(Action action)
        {
            if (CurrentDispatcher.CheckAccess())
            {
                action();

                return(Task.CompletedTask);
            }
            else
            {
                return(CurrentDispatcher.InvokeAsync(action).Task);
            }
        }
예제 #3
0
 public override async Task <TResult> InvokeAsync <TResult>(Func <Task <TResult> > workItem)
 {
     try
     {
         if (CurrentDispatcher.CheckAccess())
         {
             return(await workItem());
         }
         else
         {
             return(await CurrentDispatcher.InvokeAsync(workItem).Task.Unwrap());
         }
     }
     catch (Exception ex)
     {
         // TODO: Determine whether this is the right kind of rethrowing pattern
         // You do have to do something like this otherwise unhandled exceptions
         // throw from inside Dispatcher.InvokeAsync are simply lost.
         _ = CurrentDispatcher.BeginInvoke(RethrowException, ex);
         throw;
     }
 }
예제 #4
0
 public override bool CheckAccess()
 => CurrentDispatcher.CheckAccess();