public async Task InvokeAsync(Action action, DispatcherPriority priority = DispatcherPriority.Normal, CancellationToken ct = default) { ThrowOnInvokeIfStateIsInvalid(); var workItem = new DispatcherItem(action); _queues[(Int32)priority].Enqueue(workItem); _newWorkSemaphore.Release(); var result = await workItem.WaitAsync(ct); if (result is Exception ex) { throw ex; } }
public async Task <TResult> InvokeAsync <TResult>(Func <TResult> func, DispatcherPriority priority = DispatcherPriority.Normal, CancellationToken ct = default) where TResult : class { ThrowOnInvokeIfStateIsInvalid(); var workItem = new DispatcherItem(func); _queues[(Int32)priority].Enqueue(workItem); _newWorkSemaphore.Release(); var result = await workItem.WaitAsync(ct); if (result is Exception ex) { throw ex; } return((TResult)result); }