委托开启线程,Lamabda回调
static int Thread1(int a,int b) {
     Console.WriteLine("Thread1");
     return a + b;
}

Func<int, int, int> th = Thread1;
th.BeginInvoke(5, 3, ar =>
{
    int result = th.EndInvoke(ar);
    Console.WriteLine("结果:" + result);
}, null);

ar是IAsyncResult类型自动传给回调函数的

EndInvoke(ar) 获取线程(委托方法)的返回值


首页 我的博客
粤ICP备17103704号