public static void Main(string[] args)
        {
            Console.WriteLine("Executing Main() On Thread: {0}", Thread.CurrentThread.ManagedThreadId);
            Adder        myadder = new Adder(Add);
            IAsyncResult result  = myadder.BeginInvoke(10, 50, null, null);

            Console.WriteLine("Doing More Work In Main().");

            // block until the EndInvoke completes
            int sum = myadder.EndInvoke(result);

            Console.WriteLine("Sum: {0}", sum);
            Console.WriteLine("Exiting Main()");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Executing Main() On Thread: {0}", Thread.CurrentThread.ManagedThreadId);
            Adder        myadder = new Adder(Add);
            IAsyncResult result  = myadder.BeginInvoke(10, 50, new AsyncCallback(AddComplete), null);


            // wait ms and if completed return true else false
            while (!isDone)
            {
                Console.WriteLine("Doing More Work In Main().");
                Thread.Sleep(1000);
            }

            int sum = myadder.EndInvoke(result);

            Console.WriteLine("Sum: {0}", sum);
            Console.WriteLine("Exiting Main()");
            Console.ReadKey();
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Executing Main() On Thread: {0}", Thread.CurrentThread.ManagedThreadId);
            Adder        myadder = new Adder(Add);
            IAsyncResult result  = myadder.BeginInvoke(10, 50, null, null);


            // Checking if the thread is completed via IAsyncResult
            while (!result.IsCompleted)
            {
                Console.WriteLine("Doing More Work In Main().");
                Thread.Sleep(1000);
            }

            int sum = myadder.EndInvoke(result);

            Console.WriteLine("Sum: {0}", sum);
            Console.WriteLine("Exiting Main()");
            Console.ReadKey();
        }
        public static void Main(string[] args)
        {
            Console.WriteLine("Executing Main() On Thread: {0}", Thread.CurrentThread.ManagedThreadId);
            Adder        myadder = new Adder(Add);
            IAsyncResult result  = myadder.BeginInvoke(10, 50, null, null);


            // Checking if the thread is completed via IAsyncResult's Wait Handle
            WaitHandle handle = result.AsyncWaitHandle;

            // wait ms and if completed return true else false
            while (!handle.WaitOne(1000))
            {
                Console.WriteLine("Doing More Work In Main().");
            }

            int sum = myadder.EndInvoke(result);

            Console.WriteLine("Sum: {0}", sum);
            Console.WriteLine("Exiting Main()");
            Console.ReadKey();
        }