Code: Select all
static void Main(string[] args)
{
File.WriteAllText(@"C:\Log.txt", "");
var threads = new List<System.Threading.Thread>();
for (int i = 0; i < 3; i++)
{
var thread = new System.Threading.Thread((object arg) =>
{
int j = (int)arg;
try
{
var e = new Entities();
using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew, new TimeSpan(0, 0, 1)))
{
if (j == 0)
{
System.Threading.Thread.Sleep(1200);
}
var property = e.Properties.Single(x => x.Id == 22);
property.LastUpdateDate = DateTime.Now;
e.SaveChanges();
transactionScope.Complete();
}
}
catch (Exception ex)
{
lock (typeof(Program))
{
File.AppendAllText(@"C:\Log.txt", string.Format("{0}: {1}\r\n", DateTime.Now, ex));
}
}
});
thread.Start(i);
}
threads.ForEach(x => x.Join());
}