Action a = Test;
a.BeginInvoke(null, null);
Thread.Sleep(10);//睡眠时间
Console.WriteLine("Main");
Console.ReadKey();
通过Func<>进行新建委托
Func<string, int, int> a = Test1;
IAsyncResult ar = a.BeginInvoke("hah", 199, null, null);
Console.WriteLine("Main");
while (ar.IsCompleted)
{
Console.Write("1");
}
int res = a.EndInvoke(ar);
Console.ReadKey();
回调函数
Func<string> w = Write10;
IAsyncResult ar = w.BeginInvoke(Oncallback, w);
while (ar.IsCompleted) { }
Console.ReadKey();
static void Oncallback(IAsyncResult ar)
{
Func<string> w = (Func<string>) ar.AsyncState;
string res = w.EndInvoke(ar);
Console.WriteLine(res);
}