static void runAsynchronousCall(NetRemotingObjects.Hello obj, string name, List<string> names) { // calling synchronous methods asynchronously. // [ref] http://msdn.microsoft.com/en-us/library/2e08f6yc.aspx GreetDelegate greetDelegate = new GreetDelegate(obj.greet); IAsyncResult greetAsyncResult = greetDelegate.BeginInvoke(name, null, null); GreetAllDelegate greetAllDelegate = new GreetAllDelegate(obj.greetAll); IAsyncResult greetAllAsyncResult = greetAllDelegate.BeginInvoke(names, null, null); // do something and then wait greetAsyncResult.AsyncWaitHandle.WaitOne(); greetAllAsyncResult.AsyncWaitHandle.WaitOne(); string greeting = null; if (greetAsyncResult.IsCompleted) greeting = greetDelegate.EndInvoke(greetAsyncResult); List<NetRemotingObjects.HelloMessage> greetingMsgs = null; if (greetAllAsyncResult.IsCompleted) greetingMsgs = greetAllDelegate.EndInvoke(greetAllAsyncResult); if (null != greeting) Console.WriteLine(greeting); else Console.WriteLine("NetRemotingObjects.Hello.greet() call error"); if (null != greetingMsgs) foreach (NetRemotingObjects.HelloMessage msg in greetingMsgs) Console.WriteLine(msg.Message); else Console.WriteLine("NetRemotingObjects.Hello.greetAll() call error"); }
static void runAsynchronousCall(NetRemotingObjects.Hello obj, string name, List <string> names) { // calling synchronous methods asynchronously. // [ref] http://msdn.microsoft.com/en-us/library/2e08f6yc.aspx GreetDelegate greetDelegate = new GreetDelegate(obj.greet); IAsyncResult greetAsyncResult = greetDelegate.BeginInvoke(name, null, null); GreetAllDelegate greetAllDelegate = new GreetAllDelegate(obj.greetAll); IAsyncResult greetAllAsyncResult = greetAllDelegate.BeginInvoke(names, null, null); // do something and then wait greetAsyncResult.AsyncWaitHandle.WaitOne(); greetAllAsyncResult.AsyncWaitHandle.WaitOne(); string greeting = null; if (greetAsyncResult.IsCompleted) { greeting = greetDelegate.EndInvoke(greetAsyncResult); } List <NetRemotingObjects.HelloMessage> greetingMsgs = null; if (greetAllAsyncResult.IsCompleted) { greetingMsgs = greetAllDelegate.EndInvoke(greetAllAsyncResult); } if (null != greeting) { Console.WriteLine(greeting); } else { Console.WriteLine("NetRemotingObjects.Hello.greet() call error"); } if (null != greetingMsgs) { foreach (NetRemotingObjects.HelloMessage msg in greetingMsgs) { Console.WriteLine(msg.Message); } } else { Console.WriteLine("NetRemotingObjects.Hello.greetAll() call error"); } }