コード例 #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();