當您創建MonitorCallback
實例時,您將事件訂閱到要寫入的事件處理函數。語法看起來是這樣的,
public class MonitorCallbackFactory{
public MonitorCallback CreateCallback(){
// create the callback instance
var callback = new MonitorCallback();
// subscribe the events to the EventHandler.
callback.ApplyAccepted += OnApplyAccepted;
callback.ApplyRejected += OnApplyRejected;
return callback;
}
protected virtual void OnApplyAccepted(object sender, ApplyEventArgs e){
// the sender is always the type of object that raises the event, so
// if you need it strongly typed you can do:
var callback = (MonitorCallback)sender;
// then write your code for what happens when
// the ApplyAccepted event is raised here
}
protected virtual void OnApplyRejected(object sender, ApplyEventArgs e){
// write your code for what happens when
// the ApplyRejected event is raised here
}
}
正如你可以看到+=
是訂閱一個處理一個事件的語法。 -=
是取消訂閱和事件處理程序的語法。
雖然我不是不利於幫助你,你能不能要求你的團隊中的人寫他們? – 2011-04-04 14:14:29