.net多线程 委托的异步调用

 1  Action<string> action = this.DoSomethingLong;
 2 
 3             IAsyncResult asyncResult = null;
 4 
 5             AsyncCallback callback = ia =>
 6             {
 7                 //Console.WriteLine(object.ReferenceEquals(asyncResult, ia));
 8                 //Console.WriteLine(ia.AsyncState);
 9                 //Console.WriteLine($"到这里计算已经完成了。{Thread.CurrentThread.ManagedThreadId.ToString("00")}。");
10             };
11             asyncResult = action.BeginInvoke("btnAsyncAdvanced_Click", callback, "hao");

beginInvoke 第一个参数:委托方法的参数

第二个参数:执行异步方法结束后回调方法,参数就是异步方法的返回值,

第三个参数:向回调方法里传入的参数

猜你喜欢

转载自www.cnblogs.com/Spinoza/p/10946148.html