title: Button.PerformClick() doesn't wait an async event hanlder
body: <p>I have a problem in a Windows Forms application where I use <code>PerformClick</code> to call an <code>async</code> event handler. It seems that the event handler doesn't <code>await</code> but just returns immediately. I have created this simple application to show the problem (it's just a form with 3 buttons, easy to test yourself):</p>
  
  <pre><code>string message = "Not Started";
  
  private async void button1_Click(object sender, EventArgs e)
  {
      await MyMethodAsync();
  }
  
  private void button2_Click(object sender, EventArgs e)
  {
      button1.PerformClick();
      MessageBox.Show(message);
  }
  
  private void button3_Click(object sender, EventArgs e)
  {
      MessageBox.Show(message);
  }
  
  private async Task MyMethodAsync()
  {
      message = "Started";
      await Task.Delay(2000);
      message = "Finished";
  }
  </code></pre>
  
  <p>The interesting problem here is, what do you think <code>message</code> shows, when I click <code>Button2</code>?
  <strong>Surprisingly,</strong> it shows "Started", not "Finished", as you would expect. In other Words, it doesn't <code>await MyMethod()</code>, it just starts the Task, then continues.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>In this simple code I can make it Work by calling <code>await Method()</code> directly from Button2 event handler, like this:</p>
  
  <pre><code>private async void button2_Click(object sender, EventArgs e)
  {
      await MyMethodAsync();
      MessageBox.Show(message);
  }
  </code></pre>
  
  <p>Now, it waits 2 seconds and displays 'Finished'.</p>
  
  <p><strong>What is going on here? Why doesn't it work when using <code>PerformClick</code>?</strong>  </p>
  
  <p><strong>Conclusion:</strong></p>
  
  <p>Ok, now I get it, the conclusion is:</p>
  
  <ol>
  <li><p>Never call <code>PerformClick</code> if the eventhandler is <code>async</code>. It will not <code>await</code>!</p></li>
  <li><p>Never call an <code>async</code> eventhandler directly. It will not <code>await</code>!</p></li>
  </ol>
  
  <p>What's left is the lack of documentation on this:</p>
  
  <ol>
  <li><code>Button.PerformClick</code> should have a <strong>Warning</strong> on the doc page:</li>
  </ol>
  
  <p><a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.button.performclick?view=netframework-4.7.2" rel="nofollow noreferrer">Button.PerformClick</a> 
  "<strong>Calling PerformClick will not await async eventhandlers.</strong>"</p>
  
  <ol start="2">
  <li>Calling an <code>async void</code> method (or eventhandler) should give a compiler <strong>Warning</strong>: "<strong>You're calling an async void method, it will not be awaited!</strong>"</li>
  </ol>