public void RaiseAlarm() { if (OnAlarmRaised == null) { return; } var exceptions = new List <Exception>(); foreach (var action in OnAlarmRaised.GetInvocationList()) { try { action.DynamicInvoke(this, new AlarmEventArgs { Time = DateTime.Now }); } catch (Exception e) { exceptions.Add(e); } } if (exceptions.Any()) { throw new AggregateException(exceptions); } }
public void RaiseAlarm(string location) { List <Exception> exceptions = new List <Exception>(); foreach (Delegate handler in OnAlarmRaised.GetInvocationList()) { try { handler.DynamicInvoke(this, new AlarmEventArgs(location)); } catch (TargetInvocationException e) { exceptions.Add(e.InnerException); } } if (exceptions.Count > 0) { throw new AggregateException(exceptions); } }
public void RaiseAlarm() { List <Exception> errors = new List <Exception>(); foreach (Delegate handler in OnAlarmRaised.GetInvocationList()) { try { handler.DynamicInvoke(this, new AlarmEventArgs { Age = 28, Name = "Culai" }); } catch (TargetInvocationException tie) { errors.Add(tie.InnerException); } } if (errors.Count > 0) { throw new AggregateException(errors); } }
// Called to raise an alarm public void RaiseAlarm(string location) { List <Exception> exceptionList = new List <Exception>(); //CTO: o metodo GetInvocationList obtem todos os subscribers do delegate no cenario foram 2 foreach (Delegate handler in OnAlarmRaised.GetInvocationList()) { try { //CTO: aqui é chamado um subscribe de cada vez handler.DynamicInvoke(this, new AlarmEventArgs(location)); } catch (TargetInvocationException e) { exceptionList.Add(e.InnerException); } } if (exceptionList.Count > 0) { throw new AggregateException(exceptionList); } }
public void RaiseAlarm(string location) { List <Exception> exceptionList = new List <Exception>(); /* The word Delegate is the abstract class that defines the behavior of delegate instances. * Once the delegate keyword has been used to create a delegate type, * objects of that delegate type will be realized as Delegate instance */ foreach (Delegate handler in OnAlarmRaised.GetInvocationList()) { try { handler.DynamicInvoke(this, new AlarmEventArgs(location)); } catch (TargetInvocationException e) { exceptionList.Add(e.InnerException); } } if (exceptionList.Count > 0) { throw new AggregateException(exceptionList); } }
public void RaiseAlarm(string location) { var exceptionList = new List <Exception>(); foreach (var @delegate in OnAlarmRaised.GetInvocationList()) { try { @delegate.DynamicInvoke(this, new AlarmEventArgs(location)); } catch (TargetInvocationException e) { exceptionList.Add(e.InnerException); } } if (exceptionList.Count > 0) { throw new AggregateException(exceptionList); } OnAlarmRaised(this, new AlarmEventArgs(location)); }