1

I am using Visual Studio 2010 Beta 2.

In Parallel.For loop I execute the same method with different parameter values. After execution processed data must be stored in the database.

But I've got an exception hat says that I could not work with the same data context from different threads.

So the question will be how to work with data context and SubmitChanges() from multiple threads?

sashaeve
  • 9,387
  • 10
  • 48
  • 61

1 Answers1

1

I would recommend creating a threadsafe structure for storing your results. Once your parallel for has completed you can read these out of the structure and push them into your linq dataset.

Spence
  • 28,526
  • 15
  • 68
  • 103
  • Thank for answer. This is something like I do now. Seems to me there is no simple method to work with db directly from multi-threads. – sashaeve Jan 24 '10 at 09:57
  • Datacontexts were never designed for multi threading. That said they are very lightweight so this isn't too much of an issue. – Spence Jan 24 '10 at 20:37