Hello,
I have a section of code like this in my application, which works fine in a single threaded environment, but when I run this in multi-threaded environment, or in two different services, it'll encounter a deadlock exception (NHibernate.Util.ADOExceptionReporter - System.Data.SqlClient.SqlException: Transaction (Process ID 55) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.)
I wonder if anyone else experienced this before.
using (TransactionScope scope = new TransactionScope())
{
........ //this part is not needed to create the deadlock
using (ISession session = sessionFactory.OpenSession())
{
Message msg = session.Get(typeof(Message ), ID) as Message;
if (msg == null)
{
msg = new Message();
msg.ID = ID;
msg.UpdateDate = xxxxxx;
session.Save(msg);
}
System.Threading.Thread.Sleep(3000);
session.Flush();
}
scope.complete()
}
Thanks,
- Sam
|