首页 > 其他 > 详细

事件扩展

时间:2015-10-31 19:57:44      阅读:241      评论:0      收藏:0      [点我收藏+]
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());

事件扩展

原文:http://www.cnblogs.com/zeroone/p/4925927.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!