• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
jili
博客园    首页    新随笔    联系   管理    订阅  订阅

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();
        }

  注:

 

posted @ 2008-12-18 11:15  jili  阅读(579)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3