using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test
{
public delegate void Test();
class Program
{
static void Main(string[] args)
{
///多播委托运行时,如果其中有一个
///方法出现异常,则停止迭代,以下是
///解决方案
Test test = A;
test += B;
///返回此委托的每个方法,是一个Delegate数组
Delegate[] delegates = test.GetInvocationList();
for (int i = 0; i < delegates.Length; i++)
{
try
{
(delegates[i] as Test)();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
static void A()
{
Console.WriteLine("A");
throw new Exception("故意制造的异常!!!");
}
static void B()
{
Console.WriteLine("B");
}
}
}