public static IServiceResponse WaitForComplete(IAsyncResult ar, bool throwOnError)
{
ProcessRequestAsyncResult result = ar as ProcessRequestAsyncResult;
if (result == null)
{
throw new ArgumentException("End called with an invalid IAsyncResult object.", "ar");
}
if (result.m_response == null)
{
if (!result.WaitForComplete())
{
throw new TimeoutException();
}
}
if (throwOnError && result.m_error != null)
{
throw new ServiceResultException(result.m_error, StatusCodes.BadInternalError);
}
return result.m_response;
}