/// <summary> /// Closes an AMQP object asynchronously. /// </summary> /// <param name="amqpObject">The object to close.</param> /// <param name="timeout">The timeout in seconds.</param> /// <returns></returns> public static Task CloseAsync(this AmqpObject amqpObject, int timeout = 60000) { TaskCompletionSource <object> tcs = new TaskCompletionSource <object>(); try { amqpObject.Closed += (o, e) => { if (e != null) { tcs.SetException(new AmqpException(e)); } else { tcs.SetResult(null); } }; amqpObject.Close(0); } catch (Exception exception) { tcs.SetException(exception); } return(tcs.Task); }