Page 1 of 1

A threading question

Posted: Thu 17 May 2012 20:17
by ashlar64
Could someone tell me if this would be safe to do?

If I had a context lets say M1. And I have two threads that will work on M1. One thread will only insert elelments into M1.TestTable1 and the other thread will only do Inserts on M1.TestTable2....will I have any issues doing this?

Re: A threading question

Posted: Fri 18 May 2012 09:16
by Zero-G.
Hey

I am not a DevArt guy, but maybe my answer will help you.
The DataContext itself is not thread safe. - So, I think, this is not a good idea.
But 2 thoughtful inputs
1) Split your DataContext into 2 Context's
2) Use Asycn Queries.

Hope this will help - Have a nice day

Re: A threading question

Posted: Fri 18 May 2012 12:54
by ashlar64
Hmm two DataContexts...interesting idea.
I was initially thinking if it wasn't thread safe then to make a bunch of Lists (each would represent a different table) and do a Insert all after all the threads were done.

But I think I like your idea with using multiple Context's and will give that a try.

Re: A threading question

Posted: Mon 21 May 2012 07:34
by MariiaI
DataContext objects are not thread-safe, at least because the DataContext instance uses a single connection, which is not thread-safe itself.
You can use two DataContext instances, as Zero-G. has advised.
JIC: generally, it is recommended to use a new DataContext object per each unit of work instead of keeping it for a long time.