事件 示例 武胜

public static void Raise<T>(this EventHandler<T> handler, object sender, T args)
    where T : EventArgs
{
    if (handler != null)
    {
        handler(sender, args);
    }
}

public static void Raise(this EventHandler handler, object sender,
                         EventArgs args)
{
    if (handler != null)
    {
        handler(sender, args);
    }
}

then just call

myEvent.Raise(this, args);

That will work for all EventHandler and EventHandler<T> events.
原文地址:https://www.cnblogs.com/zeroone/p/3037000.html