public static event EventHandler<TestEventArgs> test; public static void Main() { test += TestMethod1; test += TestMethod2; test += TestMethod3; test += TestMethod4; test(null,new TestEventArgs()); Console.Read(); } private static void TestMethod1(object sender, TestEventArgs e) { Thread.Sleep(1000); Console.WriteLine("Method1"); e.Number++; Console.WriteLine(e.Number); } private static void TestMethod2(object sender, TestEventArgs e) { Console.WriteLine("Method2"); e.Number++; Console.WriteLine(e.Number); } private static void TestMethod3(object sender, TestEventArgs e) { Console.WriteLine("Method3"); e.Number++; Console.WriteLine(e.Number); } private static void TestMethod4(object sender, TestEventArgs e) { Console.WriteLine("Method4"); e.Number++; Console.WriteLine(e.Number); } public class TestEventArgs : EventArgs { public int Number { get; set; } } }
多个委托按照顺序执行,且EventArgs共用