public static void TryThreads() { List <string> commonResource = new List <string>(); Thread childThread = new Thread(() => FindingPrimNumber.IsPrimInefficient(10, commonResource)); childThread.Name = "Child Thread"; childThread.Start(); FindingPrimNumber.IsPrim(9, commonResource); foreach (var info in commonResource) { Console.WriteLine(info); } }
public static void TryTasks() { List <string> commonResource = new List <string>(); Console.WriteLine("Pornim primul task!"); Task.Run(() => FindingPrimNumber.IsPrimInefficient(9, commonResource)); Console.WriteLine("Pornim al II-lea task!"); Task.Run(() => FindingPrimNumber.IsPrim(10, commonResource)); Console.WriteLine("Asteptam 8 secunde pentru a fi terminate operatiile asincrone!"); Thread.Sleep(7000); foreach (var info in commonResource) { Console.WriteLine(info); } }
public static void FirstWorkerDoWork(object sender, DoWorkEventArgs e) { var arg = (List <string>)e.Argument; FindingPrimNumber.IsPrim(9, arg); }