Пример #1
0
        private void cmdAsync_Click(object sender, System.EventArgs e)
        {
            // Create the delegate
            GreetingDelegate delg = new GreetingDelegate(GetGreeting);

            // Make the async call
            int          threadId = 0;
            int          delay    = Convert.ToInt32(txtDelay.Text);
            IAsyncResult ar       = delg.BeginInvoke(txtName.Text, delay, out threadId, new AsyncCallback(CallbackMethod), delg);
        }
Пример #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");
            */
        }
Пример #4
0
 public IAsyncResult BeginGreet(string name, AsyncCallback callback, object state)
 {
     GreetingDelegate caller = new GreetingDelegate(() => Greet(name));
     return caller.BeginInvoke(callback, state);
 }