title: How to wait for async method to complete?
body: <p>I'm writing a WinForms application that transfers data to a USB HID class device.  My application uses the excellent Generic HID library v6.0 which can be found <a href="http://janaxelson.com/hidpage.htm#MyExampleCode" rel="noreferrer">here</a>.  In a nutshell, when I need to write data to the device, this is the code that gets called:</p>
  
  <pre><code>private async void RequestToSendOutputReport(List&lt;byte[]&gt; byteArrays)
  {
      foreach (byte[] b in byteArrays)
      {
          while (condition)
          {
              // we'll typically execute this code many times until the condition is no longer met
              Task t = SendOutputReportViaInterruptTransfer();
              await t;
          }
  
          // read some data from device; we need to wait for this to return
          RequestToGetInputReport();
      }
  }
  </code></pre>
  
  <p>When my code drops out of the while loop, I need to read some data from the device.  However, the device isn't able to respond right away so I need to wait for this call to return before I continue.  As it currently exists, RequestToGetInputReport() is declared like this:</p>
  
  <pre><code>private async void RequestToGetInputReport()
  {
      // lots of code prior to this
      int bytesRead = await GetInputReportViaInterruptTransfer();
  }
  </code></pre>
  
  <p>For what it's worth, the declaration for GetInputReportViaInterruptTransfer() looks like this:</p>
  
  <pre><code>internal async Task&lt;int&gt; GetInputReportViaInterruptTransfer()
  </code></pre>
  
  <p>Unfortunately, I'm not very familiar with the workings of the new async/await technologies in .NET 4.5.  I did a little reading earlier about the await keyword and that gave me the impression that the call to GetInputReportViaInterruptTransfer() inside of RequestToGetInputReport() would wait (and maybe it does?) but it doesn't seem like the call to RequestToGetInputReport() itself is waiting because I seem to be re-entering the while loop almost immediately?</p>
  
  <p>Can anyone clarify the behavior that I'm seeing?</p>