Microsoft.Protocols.TestSuites.MS_OXCRPC.MS_OXCRPCAdapter.EcDoAsyncWaitEx C# (CSharp) Method

EcDoAsyncWaitEx() public method

The method EcDoAsyncWaitEx is an asynchronous call that will not be completed by server until there are pending events on the Session Context up to a five minute duration.
public EcDoAsyncWaitEx ( IntPtr acxh, bool &isNotificationPending ) : uint
acxh System.IntPtr The unique value to be used as a CXH.
isNotificationPending bool A Boolean value indicates signals that events are pending for the client on the Session Context on the server.
return uint
        public uint EcDoAsyncWaitEx(IntPtr acxh, out bool isNotificationPending)
        {
            isNotificationPending = true;
            uint pulFlagsOut = 0;
            uint retValue = 0;
            uint maxWaitTime = (uint)Convert.ToInt32(Common.GetConfigurationPropertyValue("MaxWaitTime", this.Site));

            IntPtr rpcAsyncHandle = NativeMethods.CreateRpcAsyncHandle();
            Site.Assert.AreNotEqual<IntPtr>(IntPtr.Zero, rpcAsyncHandle, "Server should return valid asynchronous handle.");
            IntPtr pulFlagsOutPtr = Marshal.AllocHGlobal(sizeof(uint));
            try
            {
                NativeMethods.EcDoAsyncWaitEx(rpcAsyncHandle, acxh, 0, pulFlagsOutPtr);

                uint waitTime = 0;
                RPCAsyncStatus getCallstatus;
                do
                {
                    // Get the status of EcDoAsyncWaitEx call.
                    // The event has not been triggered yet, so the call should not be completed.
                    getCallstatus = (RPCAsyncStatus)NativeMethods.RpcAsyncGetCallStatus(rpcAsyncHandle);
                    if (getCallstatus != RPCAsyncStatus.RPC_S_ASYNC_CALL_PENDING)
                    {
                        break;
                    }

                    System.Threading.Thread.Sleep(1000);
                    waitTime++;
                }
                while (waitTime < maxWaitTime);
                Site.Assert.AreEqual<RPCAsyncStatus>(RPCAsyncStatus.RPC_S_OK, getCallstatus, "Invoking RpcAsyncGetCallStatus method should be successful.");

                IntPtr reply = Marshal.AllocHGlobal(sizeof(int));
                RPCAsyncStatus callCompleteStatus = (RPCAsyncStatus)NativeMethods.RpcAsyncCompleteCall(rpcAsyncHandle, reply);
                Site.Assert.AreEqual<RPCAsyncStatus>(RPCAsyncStatus.RPC_S_OK, callCompleteStatus, "Invoking RpcAsyncCompleteCall method for completing asynchronous wait should be successful.");
                retValue = (uint)Marshal.ReadInt32(reply);
                pulFlagsOut = (uint)Marshal.ReadInt32(pulFlagsOutPtr);
            }
            catch (SEHException e)
            {
                retValue = NativeMethods.RpcExceptionCode(e);
            }
                                        
            isNotificationPending = pulFlagsOut == 0 ? false : true;

            if (retValue == 0 && pulFlagsOut != 0)
            {
                this.VerifyEcDoAsyncWaitExpulFlagsOut(pulFlagsOut);
            }
                                                                                                                                                                                                
            this.VerifyEcDoAsyncWaitEx(acxh, retValue);
            return retValue;
        }