Пример #1
0
        // Callback method must have same signature as AsyncCallback delegate
        private void CallbackMethod(IAsyncResult ar)
        {
            // Retrieve the delegate from the IAsyncResult
            GreetingDelegate delg = (GreetingDelegate)ar.AsyncState;

            // Call EndInvoke
            int    threadId = 0;
            string greeting = delg.EndInvoke(out threadId, ar);

            //lblGreeting.Text = greeting & " : " & "threadId = " & threadId
            greeting = greeting + " : " + "threadId = " + threadId;
            SetText(greeting, lblGreeting);
        }
Пример #2
0
        static void Main(string[] args)
        {
            RemotingConfiguration.Configure("HelloClient.exe.config");

            Hello obj = new Hello();

            if (obj == null)
            {
                Console.WriteLine("could not locate server");
                return;
            }

            // synchronous:
            // greeting = obj.Greeting("Christian");

            // asynchronous:
            GreetingDelegate d = new GreetingDelegate(obj.Greeting);

            Console.WriteLine("Starting remote method");
            IAsyncResult ar = d.BeginInvoke("Christian", null, null);

            // do some work
            Console.WriteLine("Do some other work");

            ar.AsyncWaitHandle.WaitOne();

            if (ar.IsCompleted)
            {
                greeting = d.EndInvoke(ar);
            }

            Console.WriteLine(greeting);

/*
 *       Console.WriteLine("starting long call");
 *       obj.TakeAWhile(10000);
 *       Console.WriteLine("finished long call");
 */
        }
Пример #3
0
        static void Main(string[] args)
        {
            RemotingConfiguration.Configure("HelloClient.exe.config");

            Hello obj = new Hello();

            if (obj == null)
            {
                Console.WriteLine("could not locate server");
                return;
             }

             // synchronous:
             // greeting = obj.Greeting("Christian");

             // asynchronous:
             GreetingDelegate d = new GreetingDelegate(obj.Greeting);
             Console.WriteLine("Starting remote method");
             IAsyncResult ar = d.BeginInvoke("Christian", null, null);

             // do some work
             Console.WriteLine("Do some other work");

             ar.AsyncWaitHandle.WaitOne();

             if (ar.IsCompleted)
             {
            greeting = d.EndInvoke(ar);
             }

             Console.WriteLine(greeting);

            /*
             Console.WriteLine("starting long call");
             obj.TakeAWhile(10000);
             Console.WriteLine("finished long call");
            */
        }