using System.Threading;
public static Object synchronizeVariable = "locking variable";
        static void Main()
        {
            Thread[] threads = new Thread[2];
            for (int count = 0; count < threads.Length; count++)
            {
                threads[count] = new Thread(new ThreadStart(Count));
                Console.WriteLine("before start");
                threads[count].Start();
                Console.WriteLine("after start");
            }
            Console.ReadLine();
        }
        public static void Count()
        {
            lock (synchronizeVariable)
            {
                for (int count = 1; count <= 5; count++)
                {
                    Console.Write(count + " ");
                    Monitor.PulseAll(synchronizeVariable);
                    if (count < 5)
                        Monitor.Wait(synchronizeVariable);
                }
            }
        }