Example #1
0
        }     //ClientInvokeAsync()

        /// <summary>
        /// Callback handler used in ClientInvokeMethod().
        /// </summary>
        /// <param name="ar"></param>
        public void ByRefCallBack(IAsyncResult ar)
        {
            try
            {
                ByRefDelegate d = (ByRefDelegate)((AsyncResult)ar).AsyncDelegate;
                Console.WriteLine(d.EndInvoke(ar));
                m_ResetEvent.Set();
            }//try
            catch (Exception e)
            {
                Console.WriteLine("Exception in ByRefCallBack(): {0}", e.ToString());
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            }//catch
            finally
            {
                //Unregister the channels so app can execute again.
                if (m_HttpChannel != null)
                {
                    ChannelServices.UnregisterChannel(m_HttpChannel);
                }//if

                if (m_TcpChannel != null)
                {
                    ChannelServices.UnregisterChannel(m_TcpChannel);
                } //if
            }     //finally
        }         //ByRefCallBack()
        }     //ClientInvoke

        /// <summary>
        /// Used by AsyncClient.Run() to invoke the proxy method repeatedly.
        /// </summary>
        /// <param name="obj"></param>
        public void ClientInvokeAsync(object RemoteObj)
        {
            try
            {
                if (RemoteObj == null)
                {
                    Console.WriteLine("Could not locate server.");
                    return;
                }//if

                switch (m_CallConv)
                {
                case CallingConvention.ByRef:
                {
                    AsyncCallback    cb   = new AsyncCallback(ByRefCallBack);
                    HelloServerByRef hsbr = (HelloServerByRef)RemoteObj;
                    ByRefDelegate    del  = new ByRefDelegate(hsbr.HelloMethod);
                    ForwardByRef     fbr  = new ForwardByRef();
                    IAsyncResult     ar   = del.BeginInvoke("Calling ByRef async", fbr, cb, null);
                    lock (this)
                    {
                        m_ResetEvent = new ManualResetEvent(false);
                    }//lock
                    m_ResetEvent.WaitOne();
                    if (m_ThreadNumber > 0)
                    {
                        Console.WriteLine("From thread {0}", m_ThreadNumber.ToString());
                    } //if
                    break;
                }     //case

                case CallingConvention.ByVal:
                {
                    AsyncCallback    cb   = new AsyncCallback(ByValCallBack);
                    HelloServerByVal hsbv = (HelloServerByVal)RemoteObj;
                    ByValDelegate    del  = new ByValDelegate(hsbv.HelloMethod);
                    ForwardByVal     fbv  = new ForwardByVal();
                    IAsyncResult     ar   = del.BeginInvoke("Calling ByVal async", fbv, cb, null);
                    lock (this)
                    {
                        m_ResetEvent = new ManualResetEvent(false);
                    }//lock
                    m_ResetEvent.WaitOne();
                    if (m_ThreadNumber > 0)
                    {
                        Console.WriteLine("From thread {0}", m_ThreadNumber.ToString());
                    } //if
                    break;
                }     //case
                }     //switch
            }         //try
            catch (Exception e)
            {
                Console.WriteLine("Exception in Client.ClientInvokeAsync(): {0}", e.ToString());
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            } //catch
            return;
        }     //ClientInvokeAsync()
        }     //ClientInvokeAsync()

        /// <summary>
        /// Callback handler used in ClientInvokeMethod().
        /// </summary>
        /// <param name="ar"></param>
        public void ByRefCallBack(IAsyncResult ar)
        {
            try
            {
                ByRefDelegate d = (ByRefDelegate)((AsyncResult)ar).AsyncDelegate;
                Console.WriteLine(d.EndInvoke(ar));
                m_ResetEvent.Set();
            }//try
            catch (Exception e)
            {
                Console.WriteLine("Exception in ByRefCallBack(): {0}", e.ToString());
                System.Diagnostics.Process.GetCurrentProcess().Kill();
            } //catch
        }     //ByRefCallBack()
Example #4
0
    }//ClientInvoke

    /// <summary>
    /// Used by AsyncClient.Run() to invoke the proxy method repeatedly.
    /// </summary>
    /// <param name="obj"></param>
    public void ClientInvokeAsync(object RemoteObj)
    {
      try
      {
        if (RemoteObj == null)
        {
          Console.WriteLine("Could not locate server.");
          return;
        }//if

        switch (m_CallConv)
        {
          case CallingConvention.ByRef:
          {
            AsyncCallback cb = new AsyncCallback(ByRefCallBack);
            HelloServerByRef hsbr = (HelloServerByRef)RemoteObj;
            ByRefDelegate del = new ByRefDelegate(hsbr.HelloMethod);
            ForwardByRef fbr = new ForwardByRef();
            IAsyncResult ar = del.BeginInvoke("Calling ByRef async", fbr, cb, null);
            lock(this)
            {      
              m_ResetEvent = new ManualResetEvent(false);
            }//lock
            m_ResetEvent.WaitOne();
            if (m_ThreadNumber > 0)
            {
              Console.WriteLine("From thread {0}", m_ThreadNumber.ToString());
            }//if
            break;
          }//case
          case CallingConvention.ByVal:
          {
            AsyncCallback cb = new AsyncCallback(ByValCallBack);
            HelloServerByVal hsbv = (HelloServerByVal)RemoteObj;
            ByValDelegate del = new ByValDelegate(hsbv.HelloMethod);
            ForwardByVal fbv = new ForwardByVal();
            IAsyncResult ar = del.BeginInvoke("Calling ByVal async", fbv, cb, null);
            lock(this)
            {      
              m_ResetEvent = new ManualResetEvent(false);
            }//lock
            m_ResetEvent.WaitOne();
            if (m_ThreadNumber > 0)
            {
              Console.WriteLine("From thread {0}", m_ThreadNumber.ToString());
            }//if
            break;
          }//case
        }//switch
      }//try
      catch (Exception e)
      {
        Console.WriteLine("Exception in Client.ClientInvokeAsync(): {0}", e.ToString());
        System.Diagnostics.Process.GetCurrentProcess().Kill();
      }//catch
      return;
    }//ClientInvokeAsync()
Example #5
0
 /// <summary>
 /// Constructor uses a dynamic method created by our info parser.
 /// </summary>
 /// <param name="method">Dyanmic method that applies our additions</param>
 private Info(DynamicMethod method)
 {
     this.del = (ByRefDelegate)method.CreateDelegate(typeof(ByRefDelegate));
 }
 /// <summary>
 /// Constructor uses a dynamic method created by our info parser.
 /// </summary>
 /// <param name="method">Dyanmic method that applies our additions</param>
 private Info(DynamicMethod method)
 {
     this.del = (ByRefDelegate)method.CreateDelegate(typeof(ByRefDelegate));
 }