title: Print Even and Odd numbers in c# using two thread ie even thread and odd thread
body: <p>/*My requirements is 
  one threads should print even numbers and the other should print odd numbers.
  These threads should print the numbers in order (1, 2, 3, 4, 5...)</p>
  
  <p>I have done this code but when my commenting either method countThreadOdd.Start() or countThreadEven.Start(), it is not printing only even or odd numbers.*/</p>
  
  <pre><code>class Program
  {
      static Object locker = new Object();
      static LinkedList&lt;int&gt; number = new LinkedList&lt;int&gt;();
      static int counter = 0;
      static void Main(string[] args)
      {
          Thread countThreadOdd = new Thread(oddThread);
          Thread countThreadEven = new Thread(evenThread);
  
          //Thread Start
          countThreadOdd.Start();
          countThreadEven.Start();
  
          //main thread will untill below thread is in exection mode
          countThreadOdd.Join(10);
          countThreadEven.Join(10);
  
          Console.ReadLine();
      }
  
      //Odd Thread
      public static void oddThread()
      {
          for (; counter &lt; 10; )
          {
              //Lock the another thread to enter in critial area
              lock (locker)
              {
                  if (counter % 2 != 0)
                  {
                      Console.WriteLine(counter);
                      counter++;
                  }
              }
          }
      }
  
      //Even Thread
      public static void evenThread()
      {
          for (; counter &lt; 10; )
          {
              //Lock the another thread to enter in critial area
              lock (locker)
              {
                  if (counter % 2 == 0)
                  {
                      Console.WriteLine(counter);  
                      counter++;
                  }
              }
          }
      }
  }
  </code></pre>