C# Run two methods at the same time
I want to execute this "string" at the same time one underneath the other? what's wrong? using System; using System.Threading; namespace ConsoleApplication1 { class MainClass { public static void Main() { func(); } public static void func() { // This code is on thread 1 Thread ta = new Thread(new ThreadStart(() => LoopA("MMMMMMMM MMMMMMMM"))); // create thread 2 for LoopA Thread tb = new Thread(new ThreadStart(() => LoopB("MMMMMMMMM MMMMMMMMM"))); // create thread 3 for LoopB ta.Start(); // Run LoopA on thread 2 tb.Start(); // Run LoopB on thread 3 // Join makes this thread wait until the thread being joined to has finished ta.Join(); // wait for thread 2 to finish tb.Join(); // now wait for thread 3 to finish // From this point on we know that both loops have completed } public static void LoopA(string print) { foreach (char l in print) { Console.Write(l); Thread.Sleep(25); } } public static void LoopB(string print) { Console.Write("\n"); foreach (char l in print) { Console.Write(l); Thread.Sleep(25); } } } }