Write A program To Print "INDIA" "CHINA" "INDIA",CHINA using Two Threads in C#
Arman Kumar
class Program{static EventWaitHandle chinaWaitHandle = new AutoResetEvent(false);static EventWaitHandle indiaWaitHandle = new AutoResetEvent(false);static void Main(string[] args){Thread t1 = new Thread(new ThreadStart(PrintIndia));t1.Start();Thread t2 = new Thread(new ThreadStart(PrintChina));t2.Start();}static void PrintChina(){for(int i=0;i <10;i++){chinaWaitHandle.WaitOne();Console.WriteLine("China");indiaWaitHandle.Set();}}static void PrintIndia(){for (int i = 0; i < 10; i++){ Console.WriteLine("India");chinaWaitHandle.Set();indiaWaitHandle.WaitOne();}}}}