namespace ColorControl.Shared.EventDispatcher; public static class EventExtensions { public delegate Task AsyncEventHandler(object sender, TEventArgs e, CancellationToken token); public static Task InvokeAsync(this AsyncEventHandler func, object sender, TArgs e) { return func == null ? Task.CompletedTask : Task.WhenAll(func.GetInvocationList().Cast>().Select(f => f(sender, e, CancellationToken.None))); } }