Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.67/5 (6 votes)
See more:
write a Program To Print "INDIA","CHINA","INDIA","CHINA" using Two Thread in C#

OUTPUT LIKE "INDIA"
"CHINA"
"INDIA"
"CHINA"
Posted
v2
Comments
Christian Graus 22-Aug-12 6:57am    
I would not have guessed from your other questions that you use CP to cheat on your schoolwork, so, is this a task in a book you're learning from ? You seem to be writing web apps, threads are useless here. However, in general, no-one is going to answer your request to write a program for you.
ridoy 22-Aug-12 7:17am    
now homework comes here for solve!
M@anish 22-Aug-12 7:31am    
NO Dear Its A Interview Question For Technical Round
Legor 22-Aug-12 7:27am    
This is not a question.
ridoy 22-Aug-12 7:35am    
anwer isn't so tough..creat 2 thread.1 thread contains "india" text and another one for "china".Then start thread 1 first,then start thread 2.If there are criteria how many times they will execute then define it.

C#
using System;
using System.Threading;

public class Test
{
    static void Main()
    {
        // make instance


        
        Thread objTh1 = new Thread();
       Thread objTh2 = new Thread();
         objTh1.Start(threadJob1);
          objTh1.Start(threadJob2); 


    }

    public static void threadJob1()
    {
           Console.WriteLine("CHINA");
            Console.ReadLine();

    }
   public static void threadJob2()
    {
           Console.WriteLine("INDIA");
           Console.ReadLine();

    }
    

}
 
Share this answer
 
This is not a good example of how to handle threading - to get the required output from two separate threads means that you need to pause one thread until the other has done something, then pause that until the first has done something else.

It's not impossible, or even particularly difficult, but it is a bad example of what to do with threads.

If your homework requires this, then start reading at MSDN: Threading Tutorial[^] - if you look at the section "Example 2: Synchronizing two threads: a producer and a consumer" you will find code you can adjust to do what you need.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900