New transaction is not allowed because there are other threads running in the session. Entity Framework
<p>I have this simple code :</p>

<pre><code>foreach(var myvar in _sdb.Vars)
{
    myvar.Area= AreaCheck(myvar);

    _sdb.Entry(myvar).State = System.Data.Entity.EntityState.Modified;
    _sdb.SaveChanges();
}
</code></pre>

<p>When I run this code I get this exception :</p>

<blockquote>
  <p>New transaction is not allowed because there are other threads
  running in the session.</p>
</blockquote>

<p>I googled the problem, one of the answers told me to change this line : </p>

<pre><code>foreach(var myvar in _sdb.Vars)
</code></pre>

<p>To this line : </p>

<pre><code>foreach(var myvar in _sdb.Vars.ToList())
</code></pre>

<p>But when I did it, the code didn't work at all. How can I make this work? Thanks.</p>