コード例 #1
0
        public void Tocar(string apartamento)
        {
            List <Exception> erros = new List <Exception>();

            foreach (var manipulador in OnCampainhaTocou.GetInvocationList())
            {
                try
                {
                    manipulador.DynamicInvoke(this, new CampainhaEventArgs(apartamento));
                }
                catch (Exception e)
                {
                    erros.Add(e.InnerException);
                }
            }

            throw new AggregateException(erros);
        }
コード例 #2
0
        public void Tocar(string apartamento)
        {
            List <Exception> listaExcecoes = new List <Exception>();

            foreach (Delegate handler in OnCampainhaTocou.GetInvocationList())
            {
                try
                {
                    handler.DynamicInvoke(this, new CampainhaEventArgs(apartamento));
                }
                catch (TargetInvocationException e)
                {
                    listaExcecoes.Add(e.InnerException);
                }
            }

            if (listaExcecoes.Count > 0)
            {
                throw new AggregateException(listaExcecoes);
            }
        }