using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TelegramBotBase.Base { public static class Async { public delegate Task AsyncEventHandler(object sender, TEventArgs e) where TEventArgs : EventArgs; public static IEnumerable> GetHandlers( this AsyncEventHandler handler) where TEventArgs : EventArgs => handler.GetInvocationList().Cast>(); public static Task InvokeAllAsync(this AsyncEventHandler handler, object sender, TEventArgs e) where TEventArgs : EventArgs => Task.WhenAll( handler.GetHandlers() .Select(handleAsync => handleAsync(sender, e))); } }