//[OneWay] public void BroadCastingInfo(string info) { if (BroadCastEvent != null) { BroadCastEventHandler tempEvent = null; int index = 1; //记录事件订阅者委托的索引,为方便标识,从1开始。 foreach (Delegate del in BroadCastEvent.GetInvocationList()) { try { tempEvent = (BroadCastEventHandler)del; tempEvent(info); } catch { Debug.WriteLine("事件订阅者" + index.ToString() + "发生错误,系统将取消事件订阅!"); BroadCastEvent -= tempEvent; } index++; } } else { Debug.WriteLine("事件未被订阅或订阅发生错误!"); } }
//[OneWay] public void BroadCastingInfo(string info) { string errText = ""; if (BroadCastEvent != null) { BroadCastEventHandler tempEvent = null; int index = 1; //记录事件订阅者委托的索引,为方便标识,从1开始。 foreach (Delegate del in BroadCastEvent.GetInvocationList()) { try { tempEvent = (BroadCastEventHandler)del; tempEvent(info); } catch (Exception ex) { errText += "事件订阅者" + index.ToString() + "发生错误,系统将取消事件订阅!\r\n"; //MessageBox.Show("事件订阅者" + index.ToString() + "发生错误,系统将取消事件订阅!"); BroadCastEvent -= tempEvent; } index++; } } else { errText += "事件未被订阅或订阅发生错误!"; //MessageBox.Show("事件未被订阅或订阅发生错误!"); } if (!errText.Equals("")) { throw new Exception(errText); } }
public void BroadCastState(object sender, BroadCastStateEventArgs eventArgs) { BroadCastEvent?.Invoke(sender, eventArgs); }