事件扩展

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);
    }
}

 用法:

myEvent.Raise(this, args);

 .//////

为了保障事件线程安全

if (SampleEvent != null)
    SampleEvent(this, new MyEventArgs());
原文地址:https://www.cnblogs.com/zeroone/p/4925927.html