Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Gray;
            var manipulator = new ThreadManipulator();

            var addOneThr1 = new Thread(manipulator.AddingOne);
            var addOneThr2 = new Thread(manipulator.AddingOne);

            var addCustThr = new Thread(manipulator.AddingCustomValue);

            var stopThr = new Thread(manipulator.Stop)
            {
                IsBackground = true
            };

            stopThr.Start();

            addOneThr1.Start(10);
            addOneThr2.Start(20);
            // addCustThr.Start( new[]{15, 5} );
            addCustThr.Start(new[] { 5, 15 });
            addOneThr1.Join();
            addOneThr2.Join();
            addCustThr.Join();

            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //use Console.ForegroundColor = ConsoleColor.Gray for output
            var manipulator = new ThreadManipulator();
            //create ThreadManipulator object
            var ThreadOne  = new Thread(manipulator.AddingOne);
            var ThreadTwo  = new Thread(manipulator.AddingOne);
            var CustThread = new Thread(manipulator.AddingCustomValue);
            var StopThread = new Thread(manipulator.Stop)
            {
                IsBackground = true
            };

            //create first thread for AddingOne method
            //create second thread for AddingOne method

            //create thread for AddingCustomValue method

            //create Background thread for Stop method
            StopThread.Start();
            ThreadOne.Start(10);
            ThreadTwo.Start(20);
            CustThread.Start(new[] { 5, 15 });
            ThreadOne.Join();
            ThreadTwo.Join();
            CustThread.Join();
            //start Background thread for Stop method

            //start first thread for AddingOne method with argument = 10
            //start second thread for AddingOne method with argument = 20

            //start thread for AddingCustomValue method with argument new[] { 5, 15 }

            //join threads

            Console.ReadKey();
        }