title: EF Core - A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe
body: <p>I am using <code>EF Core 2.1</code> and I am trying to update multiple entities in one go by using <code>Tasks</code> (TPL):</p>
  
  <pre><code>public async Task UpdateAttendance(IEnumerable&lt;MyEvents&gt; events)
  {
      try
      {
          var tasks = events.Select(async entity =&gt;
          {
              await Task.Run(() =&gt; Context.Entry(entity).Property(x =&gt; x.Attendance).IsModified = true);
              await Context.SaveChangesAsync();
          });
  
          await Task.WhenAll(tasks);
      }
      catch (Exception ex)
      {
          throw new Exception(ex.Message ?? ex.InnerException.Message);
      }
  }
  </code></pre>
  
  <p>But this throwing the below error.</p>
  
  <blockquote>
    <p>A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe.</p>
  </blockquote>
  
  <p>Startup.cs</p>
  
  <pre><code>services.AddScoped&lt;IMyRepository, MyRepository&gt;();
  </code></pre>
  
  <p>How do I address this?</p>