[System.Security.SecurityCritical] // auto-generated internal static IMessage EndInvokeHelper(Message reqMsg, bool bProxyCase) { AsyncResult ar = reqMsg.GetAsyncResult() as AsyncResult; IMessage retMsg = null; // used for proxy case only! if (ar == null) { throw new RemotingException( Environment.GetResourceString( "Remoting_Message_BadAsyncResult")); } if (ar.AsyncDelegate != reqMsg.GetThisPtr()) { throw new InvalidOperationException(Environment.GetResourceString( "InvalidOperation_MismatchedAsyncResult")); } if (!ar.IsCompleted) { // Note: using ThreadPoolAware to detect if this is a // ThreadAffinity or Synchronization context. ar.AsyncWaitHandle.WaitOne( Int32.MaxValue, Thread.CurrentContext.IsThreadPoolAware); } lock (ar) { if (ar.EndInvokeCalled) throw new InvalidOperationException( Environment.GetResourceString( "InvalidOperation_EndInvokeCalledMultiple")); ar.EndInvokeCalled = true; IMethodReturnMessage mrm = (IMethodReturnMessage) ar.GetReplyMessage(); Contract.Assert( mrm != null, "Reply sink should ensure we have a reply message before signalling"); // For the proxy case this is handled by RealProxy if (!bProxyCase) { Exception e = mrm.Exception; if (e != null) { // throw e; throw e.PrepForRemoting(); } else { reqMsg.PropagateOutParameters( mrm.Args, mrm.ReturnValue); } } else { retMsg = mrm; } // Merge the call context back into the thread that // called EndInvoke CallContext.GetLogicalCallContext().Merge( mrm.LogicalCallContext); } // Will be non-null only for proxy case! return retMsg; } // EndInvokeHelper
internal static IMessage EndInvokeHelper(Message reqMsg, bool bProxyCase) { AsyncResult asyncResult = reqMsg.GetAsyncResult() as AsyncResult; IMessage message = null; if (asyncResult == null) { throw new RemotingException(Environment.GetResourceString("Remoting_Message_BadAsyncResult")); } if (asyncResult.AsyncDelegate != reqMsg.GetThisPtr()) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_MismatchedAsyncResult")); } if (!asyncResult.IsCompleted) { asyncResult.AsyncWaitHandle.WaitOne(0x7fffffff, Thread.CurrentContext.IsThreadPoolAware); } lock (asyncResult) { if (asyncResult.EndInvokeCalled) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EndInvokeCalledMultiple")); } asyncResult.EndInvokeCalled = true; IMethodReturnMessage replyMessage = (IMethodReturnMessage) asyncResult.GetReplyMessage(); if (!bProxyCase) { Exception exception = replyMessage.Exception; if (exception != null) { throw exception.PrepForRemoting(); } reqMsg.PropagateOutParameters(replyMessage.Args, replyMessage.ReturnValue); } else { message = replyMessage; } CallContext.GetLogicalCallContext().Merge(replyMessage.LogicalCallContext); } return message; }