home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / Remoting / MyHello / SimpleHelloNewAsync.cs < prev   
Encoding:
Text File  |  2000-06-23  |  1.2 KB  |  45 lines

  1. using System;
  2. using System.Runtime.Remoting;
  3. using System.Threading;
  4.  
  5. using HelloService;
  6.  
  7. public class SimpleHello
  8. {
  9.     public static ManualResetEvent evt;
  10.  
  11.     public static void Main(String[] args)
  12.     {
  13.         evt = new ManualResetEvent(false);
  14.         SimpleHello simpleHello = new SimpleHello();
  15.         simpleHello.InstanceMain(args);
  16.         evt.WaitOne();
  17.     }
  18.  
  19.     public void HelloCallBack(IAsyncResult ar)
  20.     {
  21.         HelloDelegate helloDelegate  = (HelloDelegate)ar.AsyncObject;
  22.  
  23.         String result = helloDelegate.EndInvoke(ar);
  24.         Console.WriteLine("Hello.HelloMethod returned: " + result);
  25.         evt.Set();
  26.     }
  27.  
  28.     public delegate String HelloDelegate(String name);
  29.  
  30.  
  31.     public void InstanceMain(String[] args)
  32.     {
  33.         String name = "Bill";    
  34.         RemotingServices.ConfigureRemoting("MyHello.cfg");
  35.         //RemotingServices.ConfigureRemoting("MyHello.DirectHTTP.cfg");
  36.  
  37.         Hello hello = new Hello();
  38.  
  39.         AsyncCallback asyncCallback = new AsyncCallback(this.HelloCallBack);
  40.         HelloDelegate helloDelegate = new HelloDelegate(hello.HelloMethod);
  41.  
  42.         IAsyncResult ar = helloDelegate.BeginInvoke(name, asyncCallback, null);
  43.     }
  44. }
  45.