Exemplo n.º 1
0
        static void Add(object data)
        {
            if (data is AddParams)
            {
                Console.WriteLine($"ID of thread in Add(): {Thread.CurrentThread.ManagedThreadId}");

                AddParams ap = (AddParams)data;
                Console.WriteLine($"{ap.a} + {ap.b} is {ap.a + ap.b}");

                waitHandle.Set();
            }
        }
Exemplo n.º 2
0
        static void Main()
        {
            Console.WriteLine("***** Use AutoResetEvent *****");
            Console.ForegroundColor = ConsoleColor.Cyan;

            Console.WriteLine($"ID of thread in Main(): {Thread.CurrentThread.ManagedThreadId}");

            AddParams ap = new AddParams(10, 20);
            Thread    t  = new Thread(new ParameterizedThreadStart(Add));

            t.Start(ap);

            waitHandle.WaitOne();
            Console.WriteLine("Other thread is done!");

            Console.ResetColor();
        }