title: Is it possible to await an event instead of another async method?
body: <p>In my C#/XAML metro app, there's a button which kicks off a  long-running process. So, as recommended, I'm using async/await to make sure the UI thread doesn't get blocked:</p>
  
  <pre><code>private async void Button_Click_1(object sender, RoutedEventArgs e) 
  {
       await GetResults();
  }
  
  private async Task GetResults()
  { 
       // Do lot of complex stuff that takes a long time
       // (e.g. contact some web services)
    ...
  }
  </code></pre>
  
  <p>Occasionally, the stuff happening within GetResults would require additional user input before it can continue. For simplicity, let's say the user just has to click a "continue" button.</p>
  
  <p>My question is: <strong>how can I suspend the execution of GetResults in such a way that it awaits an <em>event</em> such as the click of another button?</strong></p>
  
  <p>Here's an ugly way to achieve what I'm looking for: the event handler for the continue" button sets a flag...</p>
  
  <pre><code>private bool _continue = false;
  private void buttonContinue_Click(object sender, RoutedEventArgs e)
  {
      _continue = true;
  }
  </code></pre>
  
  <p>... and GetResults periodically polls it:</p>
  
  <pre><code> buttonContinue.Visibility = Visibility.Visible;
   while (!_continue) await Task.Delay(100);  // poll _continue every 100ms
   buttonContinue.Visibility = Visibility.Collapsed;
  </code></pre>
  
  <p>The polling is clearly terrible (busy waiting / waste of cycles) and I'm looking for something event-based.</p>
  
  <p>Any ideas?</p>
  
  <p>Btw in this simplified example, one solution would be of course to split up GetResults() into two parts, invoke the first part from the start button and the second part from the continue button. In reality, the stuff happening in GetResults is more complex and different types of user input can be required at different points within the execution. So breaking up the logic into multiple methods would be non-trivial.</p>