public void DoCallBack(CrossContextDelegate deleg)
        {
            /*DBG Console.WriteLine("public DoCallBack: targetCtx: "
             + Int32.Format(this.InternalContextID,"x")); DBG*/

            if (deleg == null)
            {
                throw new ArgumentNullException("deleg");
            }

            if ((_ctxFlags & CTX_FROZEN) == 0)
            {
                throw new RemotingException(
                          Environment.GetResourceString(
                              "Remoting_Contexts_ContextNotFrozenForCallBack"));
            }

            Context currCtx = Thread.CurrentContext;

            if (currCtx == this)
            {
                // We are already in the target context, just execute deleg
                // NOTE: If in the future we decide to leave the context
                // and reenter it for this case we will need to change
                // Context::RequestCallBack method in VM also!
                deleg();
            }
            else
            {
                // We pass 0 for target domain ID for x-context case.
                currCtx.DoCallBackGeneric(this.InternalContextID, deleg);
                GC.KeepAlive(this);
            }
        }
        } // DoCallBackFromEE

        // This is called by both the call back functions above.
        internal void DoCallBackGeneric(
            IntPtr targetCtxID, CrossContextDelegate deleg)
        {
            TransitionCall msgCall = new TransitionCall(targetCtxID, deleg);

            Message.PropagateCallContextFromThreadToMessage(msgCall);
            //DBG Console.WriteLine("CallBackGeneric starting!");
            IMessage retMsg = this.GetClientContextChain().SyncProcessMessage(msgCall);

            if (null != retMsg)
            {
                Message.PropagateCallContextFromMessageToThread(retMsg);
            }

            IMethodReturnMessage msg = retMsg as IMethodReturnMessage;

            if (null != msg)
            {
                if (msg.Exception != null)
                {
                    throw msg.Exception;
                }
            }
            //DBG Console.WriteLine("CallBackGeneric finished!");
        }
Exemple #3
0
 /// <summary>Executes code in another context.</summary>
 /// <param name="deleg">The delegate used to request the callback. </param>
 /// <PermissionSet>
 ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" />
 /// </PermissionSet>
 public void DoCallBack(CrossContextDelegate deleg)
 {
     lock (this)
     {
         if (this.callback_object == null)
         {
             Context newContext = Context.SwitchToContext(this);
             this.callback_object = new ContextCallbackObject();
             Context.SwitchToContext(newContext);
         }
     }
     this.callback_object.DoCallBack(deleg);
 }
Exemple #4
0
        internal void DoCallBackGeneric(IntPtr targetCtxID, CrossContextDelegate deleg)
        {
            TransitionCall transitionCall = new TransitionCall(targetCtxID, deleg);

            Message.PropagateCallContextFromThreadToMessage((IMessage)transitionCall);
            IMessage msg = this.GetClientContextChain().SyncProcessMessage((IMessage)transitionCall);

            if (msg != null)
            {
                Message.PropagateCallContextFromMessageToThread(msg);
            }
            IMethodReturnMessage methodReturnMessage = msg as IMethodReturnMessage;

            if (methodReturnMessage != null && methodReturnMessage.Exception != null)
            {
                throw methodReturnMessage.Exception;
            }
        }
Exemple #5
0
 internal static void DoCallBackFromEE(IntPtr targetCtxID, IntPtr privateData, int targetDomainID)
 {
     if (targetDomainID == 0)
     {
         CrossContextDelegate deleg = new CrossContextDelegate(new CallBackHelper(privateData, true, targetDomainID).Func);
         Thread.CurrentContext.DoCallBackGeneric(targetCtxID, deleg);
     }
     else
     {
         TransitionCall transitionCall = new TransitionCall(targetCtxID, privateData, targetDomainID);
         Message.PropagateCallContextFromThreadToMessage((IMessage)transitionCall);
         IMessage msg = Thread.CurrentContext.GetClientContextChain().SyncProcessMessage((IMessage)transitionCall);
         Message.PropagateCallContextFromMessageToThread(msg);
         IMethodReturnMessage methodReturnMessage = msg as IMethodReturnMessage;
         if (methodReturnMessage != null && methodReturnMessage.Exception != null)
         {
             throw methodReturnMessage.Exception;
         }
     }
 }
        public void DoCallBack(CrossContextDelegate deleg)
        {
            if (deleg == null)
            {
                throw new ArgumentNullException("deleg");
            }
            if ((this._ctxFlags & 2) == 0)
            {
                throw new RemotingException(Environment.GetResourceString("Remoting_Contexts_ContextNotFrozenForCallBack"));
            }
            Context currentContext = Thread.CurrentContext;

            if (currentContext == this)
            {
                deleg();
                return;
            }
            currentContext.DoCallBackGeneric(this.InternalContextID, deleg);
            GC.KeepAlive(this);
        }
        // This is called when EE needs to do a transition and execute some
        // code. Before calling, EE determines if this is a x-domain case.
        // targetDomainID will be 0 if it is a simple x-context call.
        internal static void DoCallBackFromEE(
            IntPtr targetCtxID, IntPtr privateData, int targetDomainID)
        {
            BCLDebug.Assert(targetCtxID != IntPtr.Zero, "Bad transition context");

            /*DBG Console.WriteLine("private DoCallBackFromEE: targetCtx: "
             + Int32.Format(targetCtxID,"x")
             + " PvtData: " + Int32.Format(privateData,"x"));DBG*/

            if (targetDomainID == 0)
            {
                CallBackHelper cb = new CallBackHelper(
                    privateData,
                    true /*fromEE*/,
                    targetDomainID);
                CrossContextDelegate ctxDel = new CrossContextDelegate(cb.Func);
                Thread.CurrentContext.DoCallBackGeneric(targetCtxID, ctxDel);
            }
            else
            {
                // for x-appdomain calls, we can't pass a delegate since that
                //   would require us to deserialize it on the other side which
                //   is not allowed for non-public methods.
                TransitionCall msgCall = new TransitionCall(targetCtxID, privateData, targetDomainID);

                Message.PropagateCallContextFromThreadToMessage(msgCall);
                //DBG Console.WriteLine("CallBackGeneric starting!");
                IMessage retMsg = Thread.CurrentContext.GetClientContextChain().SyncProcessMessage(msgCall);
                Message.PropagateCallContextFromMessageToThread(retMsg);

                IMethodReturnMessage msg = retMsg as IMethodReturnMessage;
                if (null != msg)
                {
                    if (msg.Exception != null)
                    {
                        throw msg.Exception;
                    }
                }
            }
        } // DoCallBackFromEE
 public void DoCallBack(CrossContextDelegate deleg)
 {
     Contract.Requires(deleg != null);
 }
 public void DoCallBack(CrossContextDelegate deleg)
 {
 }
Exemple #10
0
 public void DoCallBack(CrossContextDelegate deleg)
 {
     throw new NotImplementedException();
 }