void OnOperationComplete(AmqpObject link, IAsyncResult result, bool isOpen)
{
Exception completeException = null;
try
{
if (isOpen)
{
link.EndOpen(result);
}
else
{
link.EndClose(result);
}
}
catch (Exception exception)
{
if (Fx.IsFatal(exception))
{
throw;
}
completeException = exception;
}
bool shouldComplete = true;
if (completeException == null)
{
AmqpObjectState initialState = isOpen ? AmqpObjectState.OpenSent : AmqpObjectState.CloseSent;
lock (this.ThisLock)
{
shouldComplete = this.sender.State != initialState && this.receiver.State != initialState;
}
}
if (shouldComplete)
{
if (isOpen)
{
this.CompleteOpen(false, completeException);
}
else
{
this.CompleteClose(false, completeException);
}
}
}
}