我正在創建一個類庫,並在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);'在類庫裏面。 有什麼想法?