// 当有新邮件时 , 通知其他class // 往外发通知的 protected virtual void OnNewMail(NewMailEventArgs e) { //EventHandler<NewMailEventArgs> temp = Interlocked.CompareExchange(ref NewMail, null, null); //if (temp != null) temp(this, e); Interlocked.CompareExchange(ref NewMail, null, null)?.Invoke(this, e); e.Raise(this, ref NewMail); }
private void FaxMsg(Object sender, NewMailEventArgs e) { Console.WriteLine("Faxing mail message:"); Console.WriteLine($"From = {e.From}, To={e.To}, Subject={e.Subject}"); }
public void SimulateNewMail(String from, String to, String subject) { NewMailEventArgs e = new NewMailEventArgs(from, to, subject); OnNewMail(e); }