zoukankan      html  css  js  c++  java
  • WCF方法“异步调用”的“同步问题”

         在“WCF”中服务方法的调用是“异步”的,而这些异步的方法的执行顺序有先有后,只要当一部分“异步通信”全部完成之后,才能进行下一步的操作,如何使异步通信同步起来?有两种方法,一种是异步用法逐步执行,一种是通过“标志变量”协调执行。不知您是否有其它建议?

         1、顺序执行

              方法1_Async

           方法1_Completed
           方法2_Async

           方法2_Completed
           BindChart()

         2、标志变量,协调执行

               int flag=0;

    private void BindBaseDatas()
      {
      string weburl = Application.Current.Host.Source.ToString();
      weburl = weburl.Substring(0, (weburl.Length - 23)) + "/ChartsService.svc";
      MyChartsService.ChartsServiceClient client = new MyChartsService.ChartsServiceClient("CustomBinding_ChartsService1", weburl);


      client.GetMonitoringDatasEntityAsync(monitortype, monitordate_type, monitordate_value, monitortype_type, monitortype_value, meterusetype, true);

      client.GetMonitoringDatasEntityCompleted += new EventHandler<GetMonitoringDatasEntityCompletedEventArgs>(client_GetMonitoringDatasEntityCompleted);


    client.GetMonitoringDatasEntityTwoAsync(monitortype, monitordate_type, monitordate_value, monitortype_type, monitortype_value, meterusetype, false);
      client.GetMonitoringDatasEntityTwoCompleted += new EventHandler<GetMonitoringDatasEntityTwoCompletedEventArgs>(client_GetMonitoringDatasEntityTwoCompleted);



    }

    void client_GetMonitoringDatasEntityTwoCompleted(object sender, GetMonitoringDatasEntityTwoCompletedEventArgs e)
      {
      monitoringstwo = e.Result;
         if(flag==0)
         {
               flag=2;
         }
         else
         {
              BindChart(); 
              flag=0;
          }
      }

      void client_GetMonitoringDatasEntityCompleted(object sender, GetMonitoringDatasEntityCompletedEventArgs e)
      {
      monitoringsone = e.Result;
    if(flag==0)
         {
               flag=3;
         }
         else
         {
              BindChart(); 
              flag=0;
          }

      }
  • 相关阅读:
    luogu P1455 搭配购买
    浅谈筛素数
    luogu P1205 方块转换
    luogu P2241 统计方形
    luogu P1866 编号
    luogu P1042 乒乓球
    4.7清明考试(完蛋)
    LINUX 启动图形界面和查看运行级别
    密钥登录LINUX步骤
    服务命令只支持基本的LSB操作(启动、停止、重新启动、尝试重启、重新加载、强制重新加载、状态)。对于其他操作,请尝试使用systemctl。
  • 原文地址:https://www.cnblogs.com/ssol/p/2604589.html
Copyright © 2011-2022 走看看