title: How to force execution to stop till asynchronous function is fully executed?
body: <p>I'm creating a silverlight application for CRM as follow:</p>
  
  <p>1- A <strong>usercontrol</strong> which is a form is filled with data retrieved from the CRM using async/await </p>
  
  <p>2- A <strong>Print button</strong> that creates an instance of that usercontrol and prints it</p>
  
  <p>I have a problem in the <em>sequence of execution</em> that causes the Print button to print the usercontrol with no data, meaning, it's executed before the async method finishes.</p>
  
  <p><strong>My code is as follows:</strong> </p>
  
  <p><em>User control:</em> </p>
  
  <pre><code>   Public partial class ManagerContact : UserControl
       // constructor and functions
       ... 
     async private  void getData(string contactid)
      {
          // get some details of the contact 
  
              QueryExpression query = new QueryExpression();
              query.EntityName = "contact";
              ColumnSet cset = new ColumnSet();
              cset.Columns = new System.Collections.ObjectModel.ObservableCollection&lt;string&gt;(new String[] { "emailaddress1","fullname"  });  
              query.ColumnSet = cset;
  
  
              IOrganizationService service = SilverlightUtility.GetSoapService();
              var response = await service.RetrieveMultiple(query);
  
             /// PROBLEM HERE
  
              List&lt;contacts&gt; mycontactlist= new List&lt;contacts&gt;();
             // a function to fill the controls in the form with the retrieved data
              ...
           }
       }
  </code></pre>
  
  <p><em>My Print Button:</em></p>
  
  <pre><code>   private  void PrintOrExport(object sender, RoutedEventArgs e)
      {
          PrintDocument document = new PrintDocument();
  
         ManagerContact mymanager= new Common.ManagerContact(mycontactid);
  
               document.PrintPage += (s, args) =&gt;
              {
                // code here to prepare the pagevisual
              }
         document.Print("title");
       } 
  </code></pre>
  
  <p>When I click Print, a new instance of ManagerContact user control is created and execution goes through all the functions in the user control till it reaches the line </p>
  
  <pre><code>   var response = await service.RetrieveMultiple(query);
  </code></pre>
  
  <p>and then it returns back to the Print Button function and proceeds to print the page. The problem is it skips the rest of the functions where I fill the form controls with the data and so the form is printed with no data. </p>
  
  <p>I need to find a way to force execution to wait for the response to be returned and only after it gets teh response execution would go back to the main page for the rest of the print button. </p>