title: What is the best practice to fill a DataSet or DataTable asynchronously in ASP.NET?
body: <p>Given the following code, I have a few questions about best practices:</p>
  
  <pre><code>string connectionString = @"Server=(local)\sqlexpress; Database=master; Integrated Security=true;";
  
  using (SqlConnection connection = new SqlConnection(connectionString))
  {
      using (SqlDataAdapter dataAdapter = new SqlDataAdapter("select * from information_schema.columns", connection))
      {
          await connection.OpenAsync();
  
          DataTable dataTable = new DataTable();
          await Task.Run(() =&gt; dataAdapter.Fill(dataTable));
          return dataTable;
      }
  }
  </code></pre>
  
  <p>I've seen several examples that wrap the whole block of code in a Task.Run() call, but I'm not sure if that's better than calling Task.Run() only for the DataAdapter.Fill() method, which feels more flexible and specific (only using await on async tasks).</p>
  
  <p>Is the approach of calling Task.Run() on the Fill() method better than wrapping the whole code block?</p>
  
  <p>Are there any negative side-effects to calling Fill() in Task.Run()?  I'm thinking of something along the lines of losing call stack and/or exception information if Fill() has an error.</p>
  
  <p>Is there a better way to write this in ASP.NET?</p>