Пример #1
0
        static void Main(string[] args)
        {
            HelloWriter      hw1 = new HelloWriter("Nicolai", 10);
            HelloWriter      hw2 = new HelloWriter("Emil", 20);
            NeverEndingStory n   = new NeverEndingStory();

            Thread thread1 = new Thread(hw1.SayHello);
            Thread thread2 = new Thread(hw2.SayHello);
            Thread thread3 = new Thread(n.work);

            thread1.Start();
            thread2.Start();
            thread3.Start();

            thread1.Join();
            thread2.Join();
            var watch = System.Diagnostics.Stopwatch.StartNew();

            n.shallStop = true;

            thread3.Join();

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;


            Console.WriteLine("time: " + elapsedMs);
            //It takes a little less then 5 seconds for the program to stop
        }
Пример #2
0
        static void Main(string[] args)
        {
            HelloWriter hw1 = new HelloWriter("Nicolai");
            HelloWriter hw2 = new HelloWriter("Emil");

            Thread thread1 = new Thread(hw1.SayHello);
            Thread thread2 = new Thread(hw2.SayHello);

            thread1.Start();
            thread2.Start();
        }
Пример #3
0
        static void Main(string[] args)
        {
            HelloWriter hw1 = new HelloWriter("Nicolai", 10);
            HelloWriter hw2 = new HelloWriter("Emil", 20);

            Thread thread1 = new Thread(hw1.SayHello);
            Thread thread2 = new Thread(hw2.SayHello);

            thread1.Start();
            thread2.Start();

            Console.WriteLine("Hello from main");

            //it writes hello from main to begin with.
        }
Пример #4
0
        static void Main(string[] args)
        {
            HelloWriter hw1 = new HelloWriter("Nicolai", 10);
            HelloWriter hw2 = new HelloWriter("Emil", 20);
            HelloWriter hw3 = new HelloWriter("", 20);

            Thread thread1 = new Thread(hw1.SayHello);
            Thread thread2 = new Thread(hw2.SayHello);
            Thread thread3 = new Thread(NeverEndingStory);

            thread1.Start();
            thread2.Start();
            thread3.Start();

            thread1.Join();
            thread2.Join();
            thread3.Join();

            //It writes a never ending story to begin with and then it writes all the hello's where after it writes never endings story every 5 seconds
        }
Пример #5
0
        static void Main(string[] args)
        {
            /*
             * HelloWriter hw1 = new HelloWriter("Nicolai",100);
             * HelloWriter hw2 = new HelloWriter("Emil",200);
             *
             * Thread thread1 = new Thread(hw1.SayHello);
             * Thread thread2 = new Thread(hw2.SayHello);
             *
             * thread1.Start();
             * thread2.Start();
             */

            //HelloWriter hw1 = new HelloWriter("Nicolai", 100);
            //HelloWriter hw2 = new HelloWriter("Emil", 200);

            //hw1.numberOfTimesToLoop_ = 20;
            //hw2.numberOfTimesToLoop_ = 10;

            //Thread thread1 = new Thread(hw1.SayHello);
            //Thread thread2 = new Thread(hw2.SayHello);

            //thread1.Start();
            //thread2.Start();


            HelloWriter hw1 = new HelloWriter("Nicolai", 100);
            HelloWriter hw2 = new HelloWriter("Emil", 200);

            hw1.Start(30);
            hw2.Start(40);

            Thread thread1 = new Thread(hw1.SayHello);
            Thread thread2 = new Thread(hw2.SayHello);

            thread1.Start();
            thread2.Start();
        }