Remoting 异步调用 真假oneway方式
1. [OneWay]不允许有返回值、out参数。
2.接口里ITuxedoObject不加入[OneWay]属性,只在在TuxedoObject中加入[OneWay],编译正常,从测试的结果看,仍相当于普通回调异步,而非单向异步。
server:
using System.Runtime.Remoting.Messaging;
public interface ITuxedoObject
{
//bool ExecuteTuxedo(string[] EnvList, string Service, string Param, out string Output);
string sf();
[OneWay]
void vf(int i);
string f3(int i);
}
public class Test : System.MarshalByRefObject, ITuxedoObject
{
public string sf()
{
return "oooooooookkkkkkkkkkkk";
}
[OneWay]
public void vf(int i)
{
System.Threading.Thread.Sleep(i * 1000);
return;
}
[OneWay]
public string f3(int i)
{
i++;
System.Threading.Thread.Sleep(i*1000);
return i.ToString();
}
}
client:
delegate void AsyncCallerDelegate2(int myParam);
private void button3_Click(object sender, EventArgs e)
{
string uri = "TCP://172.20.18.193:18091/LinkoSky.TuxedoServer";
ITuxedoObject iT = (ITuxedoObject)Activator.GetObject(typeof(ITuxedoObject), uri);
AsyncCallerDelegate2 myDelegate = new AsyncCallerDelegate2(iT.vf);
DateTime d1 = DateTime.Now;
int i = Convert.ToInt32(this.textBox1.Text.Trim());
//通过Delegate的BeginInvoke()方法来调用Remote method,并输入参数(这里传入参数1)
IAsyncResult myAsyncres = myDelegate.BeginInvoke(i, null, null);
//调用EndInvoke()方法来完成异步调用过程,同时获取Remote method的返回结果
myDelegate.EndInvoke(myAsyncres);
myAsyncres = myDelegate.BeginInvoke(i, null, null);
myDelegate.EndInvoke(myAsyncres);
DateTime d2 = DateTime.Now;
TimeSpan ts = d2 - d1;
this.button3.Text = ts.TotalSeconds.ToString();
}
注:
浙公网安备 33010602011771号