事件

//定义事件
public
event EventHandler<EventArgs> ExamStarted;
//触发事件时,应防止检测事件不为空,但检测后却为空的可能性。用赋值给一个变量来防止
protected virtual void OnExamStarted()
{
    ExamEventHandler handler;
 
    try {
        handler = ExamStarted;
 
        // Invoke the event
        if (handler != null)
        {
            handler(this, EventArgs.Empty);
        }
    } 
    catch (System.Exception exception) 
    {
        // do something to handle the exception
    }
}

 

public class EventArgsT<t>: EventArgs
{
    public EventArgsT(t Target)
    {
        TargetObject = Target;
    }

    public t TargetObject
    {
        get; set
    }

}

 

 
posted on 2015-10-04 10:15  武胜-阿伟  阅读(153)  评论(0编辑  收藏  举报