title: Task Factory for each loop with await
body: <p>I'm new to tasks and have a question regarding the usage. Does the Task.Factory fire for all items in the foreach loop or block at the 'await' basically making the program single threaded? If I am thinking about this correctly, the foreach loop starts all the tasks and the .GetAwaiter().GetResult(); is blocking the main thread until the last task is complete. </p>
  
  <p>Also, I'm just wanting some anonymous tasks to load the data. Would this be a correct implementation? I'm not referring to exception handling as this is simply an example.</p>
  
  <p>To provide clarity, I am loading data into a database from an outside API. This one is using the FRED database. (<a href="https://fred.stlouisfed.org/" rel="nofollow noreferrer">https://fred.stlouisfed.org/</a>), but I have several I will hit to complete the entire transfer (maybe 200k data points). Once they are done I update the tables, refresh market calculations, etc. Some of it is real time and some of it is End-of-day. I would also like to say, I currently have everything working in docker, but have been working to update the code using tasks to improve execution.</p>
  
  <pre><code>class Program
  {
      private async Task SQLBulkLoader() 
      {
  
          foreach (var fileListObj in indicators.file_list)
          {
              await Task.Factory.StartNew(  () =&gt;
              {
  
                  string json = this.GET(//API call);
  
                  SeriesObject obj = JsonConvert.DeserializeObject&lt;SeriesObject&gt;(json);
  
                  DataTable dataTableConversion = ConvertToDataTable(obj.observations);
                  dataTableConversion.TableName = fileListObj.series_id;
  
                  using (SqlConnection dbConnection = new SqlConnection("SQL Connection"))
                  {
                      dbConnection.Open();
                      using (SqlBulkCopy s = new SqlBulkCopy(dbConnection))
                      {
                        s.DestinationTableName = dataTableConversion.TableName;
                        foreach (var column in dataTableConversion.Columns)
                            s.ColumnMappings.Add(column.ToString(), column.ToString());
                        s.WriteToServer(dataTableConversion);
                      }
  
                    Console.WriteLine("File: {0} Complete", fileListObj.series_id);
                  }
               });
          }            
      }
  
      static void Main(string[] args)
      {
          Program worker = new Program();
          worker.SQLBulkLoader().GetAwaiter().GetResult();
      }
  }
  </code></pre>