Here I am using multi threading and linq to sql.
Here I upload my code snippet:
public class PostService
{
MessageRepository objFbPostRespository = new MessageRepository();
public void callthreads()
{
for (int i = 0; i < 100; i++)
{
Thread th = new Thread(postingProcess);
th.Start();
}
}
public void postingProcess()
{
objFbPostRespository.AddLog("Test Multithread", DateTime.Now);
}
}
Message Repository class
class MessageRepository
{
DataClassesDataContext db_Context = new DataClassesDataContext();
public void AddLog(string Message, DateTime CurrentDateTime)
{
FbMessgaeLog FbMessage = new FbMessgaeLog
{
Message = Message,
Time = CurrentDateTime
};
db_Context.FbMessgaeLogs.InsertOnSubmit(FbMessage);
db_Context.SubmitChanges();
}
}
When I run it without threads then it's work fine after include thread I was got following error msg:
Error: An item with the same key has already been added.
Thanks in advance...:)