public Task InvokeOnUIThreadAsync(Action action) { if (CurrentDispatcher.CheckAccess()) { action(); return(Task.CompletedTask); } else { return(CurrentDispatcher.InvokeAsync(action).Task); } }
public void AddMidiOutMessage(string message) { if (CurrentDispatcher == null) { return; } CurrentDispatcher.InvokeAsync(() => { midiOutMessages.Add(message); while (midiOutMessages.Count > 1000) { midiOutMessages.RemoveAt(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; } }