如何让thinkphp程序走异步回调
2017-02-25
展开全部
class Program
{
public delegate int SumCallback(int x, int y);
public int Sum(int x, int y)
{
Console.WriteLine("等待...");
System.Threading.Thread.Sleep(2000);
return x + y;
}
public void Callback(IAsyncResult ar)
{
Console.WriteLine("回调...");
AsyncResult result = ar as AsyncResult;
if (result!=null)
{
SumCallback caller = (SumCallback)result.AsyncDelegate;
Console.WriteLine(caller.EndInvoke(result));
}
}
static void Main(string[] args)
{
SumCallback sc = new Program().Sum;
IAsyncResult result = sc.BeginInvoke(1, 2,new Program().Callback, sc);
Console.WriteLine("主线程...");
Console.ReadKey(true);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询