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;
}