title: Async method called from Task.WhenAll use DbContext and returned an error
body: <p>Hi I need some advice on async method run by Task.WhenAll().
  It's dotnet core 3 project and context and serviced are added as AddScoped.</p>
  <p>When I run DoWorksAysnc method I always get an issue  &quot;A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext. For more information on how to avoid threading issues with DbContext&quot;</p>
  <p>I understand that DbContext is not thread safe. but is there anyway I can run the DowksAsync method Concurrently..?</p>
  <p>Thanks,</p>
  <pre><code>   public async Task DoWorksAsync(List&lt;int&gt; ids)
          {
              
              if (ids.Count &gt; 0)
              {
                  var listOfTasks = new List&lt;Task&gt;();
                  foreach(var id in ids)
                  {
                      var task = Task.Run(async () =&gt; await UpdateDataById(id));
                      listOfTasks.Add(task);
                  }
                  await Task.WhenAll(listOfTasks);
              }
          }
  </code></pre>
  <p>And UpdateDataById method is</p>
  <pre><code> public async Task UpdateDataById (int id)
          {
              try
              {
  
                  //Get products from webservice
                  List&lt;Product&gt; products = await _searchService.GetItemsByIdAsync(id);
                  await _dataService.CreateTableIfNotExist(id); //Method inside is await _dbContext.Database.ExecuteSqlRawAsync(string.Format(_sqlCreateTableIfNotExist, id));
  
  
                  // UpdateProductsToDataTable method includes truncate table and bulkcopy.writeToServerAsync(tablename)
                  //await _dbContext.Database.ExecuteSqlRawAsync(string.Format(&quot;Truncate Table {0}&quot;, tableName));    
                  //await bulkcopy.WriteToServerAsync();
                
                  if (await _dataService.UpdateProductsToDataTable(id,products) == true) 
                  {
                     await _emailService.sendEmailNotificationAsync();
                  }
  
  
                  _logService.AddLog(&quot;process is done&quot;); 
  
                  _unitOfWork.SaveAsync(); //_context.SaveChangesAsync()
              }
              catch (Exception ex)
              {
                  await _logService.AddErrorLog(new ErrorLog
                  {
                      Id= id,
                      ErrorMessage = ex.Message
                  });
                  _unitOfWork.SaveAsync();
              }
          }
  </code></pre>