我正在创建一个类库,并在Windows窗体程序中使用它。 我想在程序中处理这个库的事件。 我使用这个代码:在类内部引发事件并在另一个类上使用处理函数
类的库中:
public class KSEDataServIO
{
public delegate void IsReadyForUseEventHandler(object sender, IsReadyForUseEventArgs e);
public event IsReadyForUseEventHandler IsReadyForUse;
public KSEDataServIO(){
EvArg = new IsReadyForUseEventArgs("AuthOkay");
IsReadyForUse(this, EvArg); //This is where i get the issue.
}
}
,并在窗口表我这样做:
private void button1_Click(object sender, EventArgs e) {
KSEDataServIO con = new KSEDataServIO();
con.IsReadyForUse += new KSEDataServIO.IsReadyForUseEventHandler(con_IsReadyForUse);
}
void con_IsReadyForUse(object sender, IsReadyForUseEventArgs e)
{
MessageBox.Show(e.Etat);
}
我得到一个NullReferenceException到线'IsReadyForUse(this,EvArg);'在类库里面。 有什么想法?