title: Why Does My Asynchronous Code Run Synchronously When Debugging?
body: <p>I am trying to implement a method called <code>ReadAllLinesAsync</code> using the async feature. I have produced the following code:</p>
  
  <pre><code>private static async Task&lt;IEnumerable&lt;string&gt;&gt; FileReadAllLinesAsync(string path)
  {
      using (var reader = new StreamReader(path))
      {
          while ((await reader.ReadLineAsync()) != null)
          {
  
          }
      }
      return null;
  }
  
  private static void Main()
  {
      Button buttonLoad = new Button { Text = "Load File" };
      buttonLoad.Click += async delegate
      {
          await FileReadAllLinesAsync("test.txt"); //100mb file!
          MessageBox.Show("Complete!");
      };
  
      Form mainForm = new Form();
      mainForm.Controls.Add(buttonLoad);
      Application.Run(mainForm);
  }
  </code></pre>
  
  <p>I expect the listed code to run asynchronously and as a matter of fact, it does! But only when I run the code <strong>without</strong> the Visual Studio Debugger. </p>
  
  <p>When I run the code <strong>with</strong> the Visual Studio Debugger attached, the code runs synchronously, blocking the main thread causing the UI to hang. </p>
  
  <p>I have attempted and succeeded to reproduce the problem on three machines. Each test was conducted on a 64bit machine (either Windows 8 or Windows 7) using Visual Studio 2012. </p>
  
  <p>I would like to know why this problem is occuring and how to solve it (as running without the debugger will likely hinder development). </p>