internal static void DoCallBackFromEE(IntPtr targetCtxID, IntPtr privateData, int targetDomainID) { if (targetDomainID == 0) { CallBackHelper helper = new CallBackHelper(privateData, true, targetDomainID); CrossContextDelegate deleg = new CrossContextDelegate(helper.Func); Thread.CurrentContext.DoCallBackGeneric(targetCtxID, deleg); } else { TransitionCall msg = new TransitionCall(targetCtxID, privateData, targetDomainID); Message.PropagateCallContextFromThreadToMessage(msg); IMessage message = Thread.CurrentContext.GetClientContextChain().SyncProcessMessage(msg); Message.PropagateCallContextFromMessageToThread(message); IMethodReturnMessage message2 = message as IMethodReturnMessage; if ((message2 != null) && (message2.Exception != null)) { throw message2.Exception; } } }
// 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
[System.Security.SecurityCritical] // auto-generated internal static void DoCallBackFromEE( IntPtr targetCtxID, IntPtr privateData, int targetDomainID) { Contract.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
//IMessage::SyncProcessMessage public IMessage SyncProcessMessage(IMessage msg) { BCLDebug.Assert( Thread.CurrentContext.InternalContextID == _targetCtxID, "Transition message routed to wrong context"); try { LogicalCallContext oldcctx = Message.PropagateCallContextFromMessageToThread(msg); if (_delegate != null) { _delegate(); } else { // This is the cross appdomain case, so we need to construct // the delegate and call on it. CallBackHelper cb = new CallBackHelper( _privateData, true /*fromEE*/, _targetDomainID); CrossContextDelegate ctxDel = new CrossContextDelegate(cb.Func); ctxDel(); } Message.PropagateCallContextFromThreadToMessage(msg, oldcctx); } catch (Exception e) { ReturnMessage retMsg = new ReturnMessage(e, new ErrorMessage()); retMsg.SetLogicalCallContext( (LogicalCallContext) msg.Properties[Message.CallContextKey]); return retMsg; } return this; }
public IMessage SyncProcessMessage(IMessage msg) { try { LogicalCallContext oldcctx = Message.PropagateCallContextFromMessageToThread(msg); if (this._delegate != null) { this._delegate(); } else { CallBackHelper helper = new CallBackHelper(this._eeData, true, this._targetDomainID); CrossContextDelegate delegate2 = new CrossContextDelegate(helper.Func); delegate2(); } Message.PropagateCallContextFromThreadToMessage(msg, oldcctx); } catch (Exception exception) { ReturnMessage message = new ReturnMessage(exception, new ErrorMessage()); message.SetLogicalCallContext((LogicalCallContext) msg.Properties[Message.CallContextKey]); return message; } return this; }