delegate 代理的三种调用方法
delegate string delegatehello (string a1,string a2);
delegatehello aysncallback;
string result=null;
public string hello(string a1,string a2)
{
return "hello "+a1+a2;
}
private void Page_Load(object sender, System.EventArgs e)
{
delegatehello mya=new delegatehello(hello);
//普通方式
string aa=mya("dai","zhenjun");
//采用回调方式
IAsyncResult ar = mya.BeginInvoke("dai","zhenjun", null, "caller_info");//caller_info 为调用者的信息
string aaasync=mya.EndInvoke(ar);
//异步调用
aysncallback=new delegatehello(hello);
System.AsyncCallback myCallBack = new System.AsyncCallback(CallBack);
aysncallback.BeginInvoke("异步dai","zhenjun", myCallBack, "caller_info");//caller_info 为调用者的信息
Response.Write(result);
}
public void CallBack(IAsyncResult e)
{
result = aysncallback.EndInvoke(e);
}
delegatehello aysncallback;
string result=null;
public string hello(string a1,string a2)
{
return "hello "+a1+a2;
}
private void Page_Load(object sender, System.EventArgs e)
{
delegatehello mya=new delegatehello(hello);
//普通方式
string aa=mya("dai","zhenjun");
//采用回调方式
IAsyncResult ar = mya.BeginInvoke("dai","zhenjun", null, "caller_info");//caller_info 为调用者的信息
string aaasync=mya.EndInvoke(ar);
//异步调用
aysncallback=new delegatehello(hello);
System.AsyncCallback myCallBack = new System.AsyncCallback(CallBack);
aysncallback.BeginInvoke("异步dai","zhenjun", myCallBack, "caller_info");//caller_info 为调用者的信息
Response.Write(result);
}
public void CallBack(IAsyncResult e)
{
result = aysncallback.EndInvoke(e);
}