title: multi insert use async await
body: <pre><code>public async Task BulkInsert(List&lt;WagerInfo&gt; wagers)
  {
      var tasks = wagers.Select(async x =&gt; await insert(x));
  
      await Task.WhenAll(tasks);
  }
  private Task insert(WagerInfo wager)
  {
      var sw = new Stopwatch();
  
      sw.Start();
  
      using (var db = new DBContext())
      {
          db.Wagers.Add(wager);
  
          await db.SaveChangesAsync();
      }
  
      sw.Stop();
  
      log("save one record spent : " + sw.Elapsed);
  }
  </code></pre>
  
  <p>It is a simple code for insert records. </p>
  
  <p>but the log shows saved one record spent more then one second sometimes.</p>
  
  <blockquote>
    <p>save one record spent : 00:00:00.0180819</p>
    
    <p>save one record spent : 00:00:00.0239751</p>
    
    <p>save one record spent : 00:00:00.0089301</p>
    
    <p>save one record spent : 00:00:00.0116161</p>
    
    <p>save one record spent : 00:00:00.0736537</p>
    
    <p>save one record spent : 00:00:00.0711155</p>
    
    <p>save one record spent : 00:00:03.1613426</p>
    
    <p>save one record spent : 00:00:03.1703909</p>
    
    <p>save one record spent : 00:00:03.1727551</p>
    
    <p>save one record spent : 00:00:07.8156325</p>
    
    <p>save one record spent : 00:00:07.8137410</p>
    
    <p>save one record spent : 00:00:07.8179925</p>
    
    <p>save one record spent : 00:00:00.0079545</p>
    
    <p>save one record spent : 00:00:00.0074952</p>
  </blockquote>
  
  <p>But my DBA said he doesn't catch any alert of executed time over then 4 seconds.</p>
  
  <p>why there are some records insert over then 1 second ?</p>
  
  <p>if I change insert method to ado.net will be better ?</p>