How to finish the program correctly:
class Program { static void Main(string[] args) { List<double> mass = new List<double>() { 1, 2, 3, 6, 7, 13, 21 }; Analysis analysis = new Analysis(mass); if (analysis.task1.IsAlive == false && analysis.task2.IsAlive == false) { analysis.Show_Res(); } Console.ReadKey(); } } public class Analysis { List<double> mass; public Thread task1; public Thread task2; public Analysis(List<double> mass) { this.mass = mass; task1 = new Thread(Fibonachi); task2 = new Thread(Prime_Numbers); task1.Start(); task2.Start(); } public void Show_Res() { StreamReader read1 = new StreamReader("Fibonachi.txt"); string line = ""; Console.WriteLine("Найденны числа фибоначи"); while ((line = read1.ReadLine()) != null) { Console.WriteLine(line); } read1.Close(); StreamReader read2 = new StreamReader("Prime_Numbers.txt"); Console.WriteLine("Найдены простые числа"); while ((line = read2.ReadLine()) != null) { Console.WriteLine(line); } read2.Close(); } public void Fibonachi() { StreamWriter str1 = new StreamWriter("Fibonachi.txt"); for (var i = 2; i < mass.Count; i++) { if (mass[i - 2] + mass[i - 1] == mass[i]) { str1.WriteLine(mass[i]); } } str1.Close(); task1.Abort(); } public void Prime_Numbers() { StreamWriter str = new StreamWriter("Prime_Numbers.txt"); bool prost; for (var i = 0; i < mass.Count; i++) { prost = true; for (int j = 2; j <= mass[i] / 2; j++) { if (mass[i] % j == 0) { prost = false; break; } } if (prost) { str.WriteLine(mass[i]); } } str.Close(); task2.Abort(); } }
How can I call this 3 Show_Res
method, I haven’t tried it, I don’t understand how to synchronize this damned chariot with me, for me multithreading is the most painful topic for me, please tell me. If with explanations I will be at many grateful! (