我来自唐朝
delegate string delegatehello (string a1,string a2);
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
delegatehello aysncallback;
string result=null;
public string hello(string a1,string a2)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
return "hello "+a1+a2;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
private void Page_Load(object sender, System.EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
delegatehello mya=new delegatehello(hello);
//普通方式
string aa=mya("dai","zhenjun");
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//采用回调方式
IAsyncResult ar = mya.BeginInvoke("dai","zhenjun", null, "caller_info");//caller_info 为调用者的信息
string aaasync=mya.EndInvoke(ar);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//异步调用
aysncallback=new delegatehello(hello);
System.AsyncCallback myCallBack = new System.AsyncCallback(CallBack);
aysncallback.BeginInvoke("异步dai","zhenjun", myCallBack, "caller_info");//caller_info 为调用者的信息
Response.Write(result);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
public void CallBack(IAsyncResult e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
result = aysncallback.EndInvoke(e);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)