views:

91

answers:

1

Hey,

i am considering - in order the get a high performance application - to keep a single DataContext in the cache to perform the selects and updates to...

In order the keep the responsetimes low, i'd like to create an asynchronous update like the one i scribbled below:

public void AsyncInsert()
{
  DataContext dc = new DataContext();
  dc.MessageTable.InsertOnSubmit(new Message("test1"));
  dc.MessageTable.InsertOnSubmit(new Message("test2"));
  dc.MessageTable.InsertOnSubmit(new Message("test3"));

  dc.AsynchronousSubmitChanges(); // delegate to other thread
}

Is something like this possible or even thinkable without any problem on parallel threads writing to the same DataContext?

Hope you understand what i mean

Thanks!

+1  A: 

I think you have a couple problems here. For one, a L2S database context object isn't thread safe, if I recall correctly. I've tried it with multiple threads and have had problems. Secondly, you want to keep your data context object alive for the smallest amount of time possible. It is a heavy weight object. Therefore, you want to instantiate it, do your work and release it, quickly.

Randy Minder
+1 Your data context is kind of your unit of work.
Perpetualcoder