|
ToDo:
|
using System; using System.Collections.Generic; using System.Text; using System.Threading; namespace DelegateTest { delegate void Delegatefunction(string str,int cnt); class Program { static void Main(string[] args) { Program prog = new Program(); Delegatefunction func = new Delegatefunction(prog.CallerFunction); func.BeginInvoke("Delegate", 1000,new AsyncCallback(prog.Callback), func); prog.CallerFunction("Main",2000); } public void CallerFunction(string str,int cnt) { for (int i = 0; i < 10; i++) { Thread.Sleep(cnt); System.Console.WriteLine(str + ":" + i); } } public void Callback(IAsyncResult ar) { // 後始末 Delegatefunction func = (Delegatefunction)ar.AsyncState; func.EndInvoke(ar); } } }