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

      }
  • 相关阅读:
    SqLite 框架 GreenDAO
    HttpClient的使用
    android事件分发介绍
    Android常见开发思路
    AndroidStudio学习记录
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo异常总结
    开源Pull_To_Refresh控件使用
    自定义控件ViewPagae<
    白龙软件商店面试问题整理
    基于anyrtc的sdk实现直播连麦互动
  • 原文地址:https://www.cnblogs.com/ssol/p/2604589.html
Copyright © 2011-2022 走看看