static void PrintResults(List <List <Krepsininkas> > teams, ParallelArray <Krepsininkas> P, string resultFile) { using (StreamWriter writer = new StreamWriter(resultFile)) { foreach (List <Krepsininkas> team in teams) { writer.WriteLine(new String('-', header1.Length)); writer.WriteLine(header1); writer.WriteLine(new String('-', header1.Length)); foreach (Krepsininkas krepsininkas in team) { writer.WriteLine(krepsininkas.ToString()); } writer.WriteLine(); } writer.WriteLine(new String('/', header1.Length)); writer.WriteLine(new String('-', header1.Length)); writer.WriteLine(header1); writer.WriteLine(new String('-', header1.Length)); for (int i = 0; i < P.count; i++) { writer.WriteLine(P.Get(i)); } } }
static void Main(string[] args) { ParallelArray <Krepsininkas> P = new ParallelArray <Krepsininkas>(50); string dataFile1 = "IFF-6-5_DambrauskasEimontas_L1a_dat.txt"; string dataFile2 = "IFF-6-5_DambrauskasEimontas_L1a_dat2.txt"; string dataFile3 = "IFF-6-5_DambrauskasEimontas_L1a_dat3.txt"; string resultFile1 = "IFF-6-5_DambrauskasEimontas_L1a_rez.txt"; string resultFile2 = "IFF-6-5_DambrauskasEimontas_L1a_rez2.txt"; string resultFile3 = "IFF-6-5_DambrauskasEimontas_L1a_rez3.txt"; List <List <Krepsininkas> > teams = ReadKrepsininkai(dataFile1); Thread[] threads = new Thread[teams.Count]; for (int i = 0; i < threads.Length; i++) { int temp = i; Thread thread = new Thread(() => ExcecuteThread(teams[temp], P)); threads[temp] = thread; threads[temp].Name = "Gija Nr." + temp; threads[temp].Start(); } for (int i = 0; i < threads.Length; i++) { threads[i].Join(); } PrintResults(teams, P, resultFile1); }
static void ExcecuteThread(List <Krepsininkas> Pi, ParallelArray <Krepsininkas> P) { int j = 0; foreach (Krepsininkas krepsininkas in Pi) { if (krepsininkas.AveragePt > 4) { P.Add(krepsininkas); } } }