public void OnEmploiChanged(int id_en, string notification) { if (EmploiChanged != null) { EmploiChangedEvent notifDelegate = null; Delegate[] invocationList_ = null; try { invocationList_ = EmploiChanged.GetInvocationList(); } catch (MemberAccessException ex) { throw ex; } if (invocationList_ != null) { lock (this) { foreach (Delegate del in invocationList_) { notifDelegate = (EmploiChangedEvent)del; WrapperDelegate wrDel = new WrapperDelegate(BeginSend); AsyncCallback callback = new AsyncCallback(EndSend); wrDel.BeginInvoke(id_en, notification, notifDelegate, callback, wrDel); } } } } }
private void BeginSend(int id_en, string notification, EmploiChangedEvent notifDelegate) { try { notifDelegate(id_en, notification); } catch (Exception e) { EmploiChanged -= notifDelegate; } }
public void NotificationReceivedHandler(int id_en, string message) { ListView notifborad = emp.getNotifBoard(); if (notifborad.InvokeRequired == false) { if (loginForm.user.id_utilisateur == id_en) { notifborad.Items.Add(message); MessageBox.Show(message); } } else { // Show the text asynchronously EmploiChangedEvent statusDelegate = new EmploiChangedEvent(crossThreadEventHandler); this.BeginInvoke(statusDelegate, new object[] { id_en, message }); } }
public NotificationClass() { notifDelegate = new EmploiChangedEvent(OnEmploiChanged); }