public void InvokeOnUIThread(Action action) { if (CurrentDispatcher.CheckAccess()) { action(); } else { CurrentDispatcher.Invoke(action); } }
public Task InvokeOnUIThreadAsync(Action action) { if (CurrentDispatcher.CheckAccess()) { action(); return(Task.CompletedTask); } else { return(CurrentDispatcher.InvokeAsync(action).Task); } }
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; } }
public override bool CheckAccess() => CurrentDispatcher.CheckAccess();