Example #1
0
        public static void Main(string[] args)
        {
            NumberCounter nc = new NumberCounter();
            Thread        t1 = new Thread(Run4);
            Thread        t2 = new Thread(Run4);

            t1.Start(nc);
            t2.Start(nc);
        }
Example #2
0
        public static void Run4(object o)
        {
            NumberCounter nc = (NumberCounter)o;

            for (int i = 0; i < 100; i++)
            {
                lock (nc)
                {
                    nc.Change();
                    nc.Show();
                }
                Thread.Sleep(100);
            }
        }