Exemplo n.º 1
0
        public static void StartThread(delg d)
        {
            ThreadStart ts = new ThreadStart(d);
            Thread      t  = new Thread(ts);

            t.Start();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");
            delg d = new delg(Callbytext);

            d += Callbyphone;
            d += Callbytmeet;
            d("Done!!");
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            startBruteForce(2);
            while (toProcess.Count > 0)
            {
                delg nextToProcess = toProcess.Pop();
                StartThread(nextToProcess);
            }


            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            //delegate has a pointer in the stack
            //that refers the value in the heap
            delg var2 = () => Console.WriteLine("I am a delegate");

            //enum is in the stack
            Color var3 = Color.magenta;

            //class has a pointer in the stack
            //that refers the value in the heap
            Pizza var4 = new Pizza {
                IsEatable = true, IsVeg = false
            };

            //struct is in the stack
            Salad var5 = new Salad {
                IsEatable = true, IsVeg = false
            };

            //interface can point to the stack or to the heap
            IEatable var0 = var4;  //interface points to class (heap)
            IEatable var1 = var5;  //interface points to struct (stack)


            Console.WriteLine($"var0.IsEatable {var0.IsEatable} before function");
            Console.WriteLine($"var1.IsEatable {var1.IsEatable} before function");

            functionChangeIEatable(var0);
            functionChangeIEatable(var1);

            Console.WriteLine($"var0.IsEatable {var0.IsEatable} after function");
            Console.WriteLine($"var1.IsEatable {var1.IsEatable} after function");
            Console.WriteLine("-----------------------------");
            Console.WriteLine($"functionChangePizza {var4.IsEatable} before function");
            functionChangePizza(var4);
            Console.WriteLine($"functionChangePizza {var4.IsEatable} after function");
            Console.WriteLine("-----------------------------");
            Console.WriteLine($"functionChangeSalad {var5.IsEatable} before function");
            functionChangeSalad(var5);
            Console.WriteLine($"functionChangeSalad {var5.IsEatable} after function");
        }
        static void Main(string[] args)
        {
            //delegate has a pointer in the stack
            //that refers the value in the heap
            delg var2 = () => Console.WriteLine("I am a delegate");

            //enum is in the stack
            Color var3 = Color.magenta;

            //class has a pointer in the stack
            //that refers the value in the heap
            Pizza var4 = new Pizza {
                IsEatable = true, IsVeg = false
            };

            //struct is in the stack
            Salad var5 = new Salad {
                IsEatable = true, IsVeg = false
            };

            //interface can point to the stack or to the heap
            IEatable var0 = var4;  //interface points to class (heap)
            IEatable var1 = var5;  //interface points to struct (stack)
        }
Exemplo n.º 6
0
        static void ThreadExamples(string[] args)
        {
            /*{
             *  ThreadStart ts = new ThreadStart(PrintOutOnes);     //Create a thread start given delegate
             *  Thread t = new Thread(ts);                          //Create thread with threadstart
             *  //t.Priority = ThreadPriority.Highest;
             *  t.Start();                                          //Start the thread
             * }
             *
             * {
             *  ThreadStart ts = new ThreadStart(PrintOutZeros);     //Create a thread start given delegate
             *  Thread t = new Thread(ts);                          //Create thread with threadstart
             *  t.Start();                                          //Start the thread
             * }
             *
             * {
             *  ThreadStart ts = new ThreadStart(GoatNoises);     //Create a thread start given delegate
             *  Thread t = new Thread(ts);                          //Create thread with threadstart
             *  t.Start();                                          //Start the thread
             * }
             *
             * {
             *  ThreadStart ts = new ThreadStart(() => { someInt++; });     //Create a thread start given delegate
             *  Thread t = new Thread(ts);                          //Create thread with threadstart
             *  t.Start();                                          //Start the thread
             * }
             *
             * {
             *  ThreadStart ts = new ThreadStart(() => { someInt++; });     //Create a thread start given delegate
             *  Thread t = new Thread(ts);                          //Create thread with threadstart
             *  t.Start();                                          //Start the thread
             * }
             *
             * {
             *  ThreadStart ts = new ThreadStart(() => { PrintOutChar('a', 50); });
             *  Thread t = new Thread(ts);
             *  t.Start();
             * }
             *
             * {
             *  ThreadStart ts = new ThreadStart(() => { PrintOutChar('a', 50); });
             *  Thread t = new Thread(ts);
             *  t.Start();
             * }
             *
             * {
             *  ThreadStart ts = new ThreadStart(NightClub);
             *  Thread t = new Thread(ts);
             *  t.Start();
             * }
             *
             * {
             *  ThreadStart ts = new ThreadStart(NightClub);
             *  Thread t = new Thread(ts);
             *  t.Start();
             * }
             *
             * {
             *  ThreadStart ts = new ThreadStart(BiggerNightClub);
             *  Thread t = new Thread(ts);
             *  t.Start();
             * }
             *
             * {
             *  ThreadStart ts = new ThreadStart(BiggerNightClub);
             *  Thread t = new Thread(ts);
             *  t.Start();
             * }
             *
             * {
             *  ThreadStart ts = new ThreadStart(BiggerNightClub);
             *  Thread t = new Thread(ts);
             *  t.Start();
             * }*/

            List <delg> delgList = new List <delg>()
            {
                BiggerNightClub,
                BiggerNightClub,
                NightClub,
                () => someInt++,
                () => BiggerNightClub(),
                () => PrintOutChar('a', 50)
            };

            Stack <delg> toProcess = new Stack <delg>(delgList);

            while (toProcess.Count > 0)
            {
                delg nextToProc = toProcess.Pop();
                StartThread(nextToProc);
            }


            Console.WriteLine("Program finished");
            Console.ReadLine();
        }