title: Odd effect of async / await on loading a datatable
body: <p>I'm struggling to understand what is going on with this code.  I've done async/await for a while now but haven't stumbled on this issue before (unless I'm just not seeing what I've done)</p>
  <p>I'm loading a CSV file into a DataTable then I want to pull the list of column names from the DataTable to manipulate later.</p>
  <p>In the first method, I load the CSV async then assign the DataGrid to view the data.  I wasn't able to use the _ColumnList = ... in the first method because for whatever reason, the &quot;_dtSampleCSV.Columns&quot; did not resolve; it's not seeing that it's a DataTable.</p>
  <p>So I moved that line to another method where it pulls the column names and assigns those names to another DataGrid.  When it hits this method, there's no data in the _dtSampleCSV DataTable (no rows, no columns), yet the first DataGrid does populate with data.</p>
  <p>I've always assumed that using an &quot;await&quot; waits for the thread to complete before proceeding.  So either that's not true, or the thread did complete but the DataTable wasn't assigned yet.</p>
  <p>I can only assume the data doesn't exist at that point, but the DataGrid's source is set so when the data is populated; it shows.  But how do I prevent execution if await isn't completing the dataload into the DataTable?</p>
  <pre><code>private DataTable _dtSampleCSV = new DataTable();
  private List&lt;string&gt; _ColumnList = new List&lt;string&gt;();
  
  private async void btnAdd_Click(object sender, RoutedEventArgs e)
  {
      spNew.Visibility = Visibility.Visible;
  
      OpenFileDialog openFileDialog = new OpenFileDialog();
      if (openFileDialog.ShowDialog() == true)
      {
          tbFilePath.Text = openFileDialog.FileName;
          var _dtSampleCSV = await LoadCSVAsync(openFileDialog.FileName);
              
          dgCSVExample.DataContext = _dtSampleCSV;
          dgCSVExample.Visibility = Visibility.Visible;
  
          SetColumnGrid();
  
      }
  }
  
  private void SetColumnGrid()
  {
      _ColumnList = (from DataColumn dc in _dtSampleCSV.Columns.Cast&lt;DataColumn&gt;() select dc.ColumnName).ToList();
      dgColumnNames.DataContext = _ColumnList;  // breakpoint set here to look at _dtSampleCSV and no data exists at runtime
      dgColumnNames.Visibility = Visibility.Visible;
  }
  
  // csv method
  public static async Task&lt;DataTable&gt; LoadCSVAsync(string filePath)
  {
      using (var reader = File.OpenText(filePath))
      {
          var fileText = await reader.ReadToEndAsync();
          using (TextReader sr = new StringReader(fileText))
          {
              var adapter = new GenericParsing.GenericParserAdapter(sr);
              adapter.FirstRowHasHeader = true;
              adapter.MaxBufferSize = 4096;
              adapter.MaxRows = 3;
              DataTable dtProcess = adapter.GetDataTable();
              return dtProcess;
          }
      }
  }
  </code></pre>