views:

234

answers:

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?

+1  A: 

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
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
Datacontexts were never designed for multi threading. That said they are very lightweight so this isn't too much of an issue.
Spence