title: Async methods switching passing control back and forth to next async method
body: <p>I have two async methods that retrieve data from two tables in a database. During runtime, I got an error </p>
  
  <blockquote>
    <p>Collection was modified; enumeration operation may not execute</p>
  </blockquote>
  
  <p>I stepped into my code and realized something strange, the two methods switch control back and forth even before a method finishes executing. Method 1 would execute and after two or three lines, method 2 executes then after a few lines control goes back to method 1. This happens until I get that exception. Funny thing though is that while posting this, I ran the application and I got no Exception. Here are the two methods</p>
  
  <pre><code>public async void InitializeParts()
  {
      populator = new Populator();
      await Task.Run(()=&gt; detailsDataTable = new DataTable());
      string partSql = "SELECT * FROM tblparts";            
      await Task.Run(() =&gt; populator.FillDataTableAsync(partSql, detailsDataTable));
      await Task.Run(() =&gt; partDetailsDataGridView.DataSource = detailsDataTable);
      detailsCriteriaSearchBox.Text = string.Empty;
  }
  
  public async void InitializeTrack()
  {
      populator = new Populator();
      await Task.Run(() =&gt; trackDataTable = new DataTable());
      string TrackSql = "SELECT * FROM tblmodule";
      await Task.Run(() =&gt; populator.FillDataTableAsync(TrackSql, trackDataTable));
      await Task.Run(() =&gt; trackModulesDataGridView.DataSource = trackDataTable);
      trackCriteriaSearchBox.Text = string.Empty;
  }
  </code></pre>
  
  <p>I call the two  methods one after the other like this</p>
  
  <pre><code>await Task.Run(() =&gt; InitializeParts());
  await Task.Run(() =&gt; InitializeTrack()); 
  </code></pre>
  
  <p>My question is what exactly is happening as I want to handle it.</p>