static void Main(string[] args) { MyThread mt = new MyThread("Child#1"); Thread newThrd = new Thread(mt.run); newThrd.Start(); do { Console.WriteLine("."); Thread.Sleep(100); } while (mt.Count != 10); Console.WriteLine("Main thread ending!"); }
static void Main() { MyThread mt = new MyThread(); Thread t1 = new Thread(new ThreadStart(mt.Thread1)); Thread t2 = new Thread(new ThreadStart(mt.Thread1)); Thread t3 = new Thread(new ThreadStart(mt.Thread1)); t1.Start(); //it stops other threads untill it gets execute t1.Join(); t2.Start(); t3.Start(); Console.ReadKey(); }
static void Main() { MyThread mt = new MyThread(); Thread t1 = new Thread(new ThreadStart(mt.Thread1)); Thread t2 = new Thread(new ThreadStart(mt.Thread1)); Thread t3 = new Thread(new ThreadStart(mt.Thread1)); t1.Start(); //It causes all the calling threads to wait until the current thread // (joined thread) is terminated or completes its task. t2.Start(); t3.Start(); Console.ReadKey(); }