Mega Code Archive

 
Categories / C# Book / 10 Thread
 

0631 Thread

using System; using System.Threading; class ThreadTest { static void Main() { Thread t = new Thread(WriteY); // Kick off a new thread t.Start(); // running WriteY() // Simultaneously, do something on the main thread. for (int i = 0; i < 10; i++) Console.Write ("x"); } static void WriteY() { for (int i = 0; i < 10; i++) Console.Write("y"); } } The output: yyyyyyyyyyxxxxxxxxxx