Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework and multithreading

I have a WCF service that processes some messages. I use EntityFramework to retrieve the messages. I add these messages to a ThreadPool queue and then process them. After processing all the messages, I call an update on the Entity Framework to update the status of the messages.

Durng this operation, I randomly get the error - "EntityMemberChanged or EntityComplexMemberChanged was called without first calling EntityMemberChanging or EntityComplexMemberChanging on the same change tracker with the same property name. For information about properly reporting changes, see the Entity Framework documentation."

This error is thrown when the ReportPropetychanged event for a particular attribute gets fired.

Any help would be appreciated.

Regards

Andy

like image 714
Andy Avatar asked Aug 26 '10 10:08

Andy


1 Answers

Don't share an ObjectContext -- or any object attached to it -- between threads. It is documented to be non-thread-safe.

like image 157
Craig Stuntz Avatar answered Oct 10 '22 15:10

Craig Stuntz