当您创建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