You cannot use LINQ DataContext at the same time:
Any instance members are not guaranteed to have reliable flow.
Therefore, you need to either serialize access (blocking), which will be terribly inefficient, or it is better to use a separate context in each thread:
public class PostService { public void callthreads() { for (int i = 0; i < 100; i++) { Thread th = new Thread(postingProcess); th.Start(); } } public void postingProcess() { using (MessageRepository objFbPostRespository = new MessageRepository()) { objFbPostRespository.AddLog("Test Multithread", DateTime.Now); } } }
I also hope, for your own sake, that your test has real logic to wait for the test threads to complete before closing ... And, of course, correctly implement IDisposable in your repository and get rid of the context so that the DB Connection will be put back into the pool.
source share