This question is locked. New answers and comments are not allowed.
Hello,
I want to exec sql statements in multithreaded environment. When you look for the following example - why are there several Sql Statements like SET LOCK_TIMEOUT etc?
How does OA handle that?
FYI: I am using one context (in this case a repository around the OA context) per thread (task in TPL)
Thank you in advance,
Norbert
I want to exec sql statements in multithreaded environment. When you look for the following example - why are there several Sql Statements like SET LOCK_TIMEOUT etc?
internal class Program { public static int i=0; public static Object lockvar = ""; // Lock-Variable private static void Main(string[] args) { CheckTime("Initialize Application"); AppInitializer.InitializeApp(); Task t1 = new Task(DoIt); Task t2 = new Task(DoIt); Task t3 = new Task(DoIt); t1.Start(); t2.Start(); t3.Start(); Task.WaitAll(t1, t2, t3); Console.WriteLine("The end"); Console.ReadLine(); } public static void DoIt() { Thread.Sleep(2000); //simulate longer running task... lock ( lockvar ) { string mystring = "Thread started... "; i++; mystring += i; CheckTime(mystring); using ( IRepository<SysProperty> rep = App.Instance.GetService<IRepository<SysProperty>>() ) { rep.AutoCommit = false; var o = rep.AdoGetSql("Select * From dbo.tblSysProperty where name = 'DbVersion'"); CheckTime(o.First().Name.ToString()); o.First().Value = "Testwert " + i.ToString(); rep.SaveChanges(); Console.WriteLine(rep.LogOutput); } //Repository.SaveChanges(); System.Console.WriteLine("Alles gespeichert...{0}", i.ToString()); } } private static void CheckTime(string Info) { Console.WriteLine("{0} | {1}", DateTime.Now.ToString("u"), Info.ToString()); } }How does OA handle that?
FYI: I am using one context (in this case a repository around the OA context) per thread (task in TPL)
Thank you in advance,
Norbert