System.Data.Entity.Infrastructure.CommitFailedException: C# Multithreading & SQL Server 2012 System.Data.Entity.Infrastructure.CommitFailedException: C# Multithreading & SQL Server 2012 multithreading multithreading

System.Data.Entity.Infrastructure.CommitFailedException: C# Multithreading & SQL Server 2012


I used to face the same sssue.If the threaded app is using same context object for all the threads we face these kind of issues.Create separate context objects for each thread.You might be adding some more load on your RAM but it gives clarity about states of enities in Context.

List<Task> tasks = new List<Task>();foreach (var item in list){   ObjectContext oContext = new ObjectContext("MyConnection");   Task t = Task.Factory.StartNew(() =>   {      this.Update(item,oContext);   });   tasks.Add(t);}Task.WaitAll(tasks.ToArray());