ConsoleProject { class TestDelegateAsync { class MainClass { public static void Main(string[] args) { TestDelegateAsync test = new TestDelegateAsync(); TestDelegate d = test.DoWork; d.BeginInvoke(test.CallbackMethod, null); Console.ReadKey(); } } public delegate int TestDelegate(); //࣮ߦ͍ͨ͠ॲཧ public int DoWork() { Console.WriteLine("DoWork"); return 100; } //AsyncCallbackͷγάωνϟʹैͬͨίʔϧόοΫϝιου public void CallbackMethod(IAsyncResult ar) { //BeginInvokeͷ݁ՌΛͬͯɺͦͷεϨου͔Β݁ՌΛநग़ͯ͠දࣔ TestDelegate @delegate = (TestDelegate)((AsyncResult)ar).AsyncDelegate; int result = @delegate.EndInvoke(ar); Console.WriteLine(result); } } } ࣮ߦ͍ͨ͠ॲཧ͕ೖΔσϦήʔτΛ༻ҙͯ͠ ࣮ߦ͍ͨ͠ॲཧΛॻ͘ γάωνϟʹैͬͨίʔϧόοΫϝιου ͜ͷΑ͏ʹͯ݁͠ՌΛಘΒΕΔ
using System.Threading; class TPL { static void Main(string[] args) { var act = new Action[10]; for (int i = 0; i < 10; ++i) act[i] = new Action(Show); //Invokeશͯྃ͢Δ·ͰϝΠϯεϨου͕ऴྃ͠ͳ͍ Parallel.Invoke(act); Console.WriteLine("exit..."); } static void Show() { Console.WriteLine("Hello."); } }