// service bus best practices for performance:
		// http://msdn.microsoft.com/en-us/library/windowsazure/hh528527.aspx
		public void Send(ISendContext context)
		{
			_connectionHandler
				.Use(connection =>
					{
						// don't have too many outstanding at same time
						SpinWait.SpinUntil(() => _messagesInFlight < _settings.MaxOutstanding);

						using (var body = new MemoryStream())
						{
							context.SerializeTo(body);

							// the envelope is re-usable, so let's capture it in the below closure
							// as a value
							var envelope = new MessageEnvelope(body.ToArray());

							var sending = Retries.Retry(FaultPolicies.FinalAzurePolicy,
								new Func<AsyncCallback, object, IAsyncResult>((cb, state) =>
								{
									return SendMessage(connection, () =>
										{
											var brokeredMessage = new BrokeredMessage(envelope);

											if (!string.IsNullOrWhiteSpace(context.CorrelationId))
												brokeredMessage.CorrelationId = context.CorrelationId;

											if (!string.IsNullOrWhiteSpace(context.MessageId))
												brokeredMessage.MessageId = context.MessageId;

											return brokeredMessage;
										}, 1, cb, state);
								}),
								(IAsyncResult ar) =>
								{
									var state = (StateHolder)ar.AsyncState;
									Interlocked.Decrement(ref _messagesInFlight);

									try
									{
										state.Sender.EndSend(ar);
										Address.LogEndSend(state.Message.MessageId);
									}
									finally
									{
										// always dispose the message; it's only good once
										state.Message.Dispose();
									}
								});
							sending.Wait();
						}
					});
		}
        // service bus best practices for performance:
        // http://msdn.microsoft.com/en-us/library/windowsazure/hh528527.aspx
        public void Send(ISendContext context)
        {
            _connectionHandler
            .Use(connection =>
            {
                // don't have too many outstanding at same time
                SpinWait.SpinUntil(() => _messagesInFlight < _settings.MaxOutstanding);

                using (var body = new MemoryStream())
                {
                    context.SerializeTo(body);

                    // the envelope is re-usable, so let's capture it in the below closure
                    // as a value
                    var envelope = new MessageEnvelope(body.ToArray());

                    Task sending = Retries.Retry(FaultPolicies.FinalAzurePolicy,
                                                 (cb, state) =>
                    {
                        return(SendMessage(connection, () =>
                        {
                            var brokeredMessage = new BrokeredMessage(envelope);

                            if (!string.IsNullOrWhiteSpace(context.CorrelationId))
                            {
                                brokeredMessage.CorrelationId = context.CorrelationId;
                            }

                            if (!string.IsNullOrWhiteSpace(context.MessageId))
                            {
                                brokeredMessage.MessageId = context.MessageId;
                            }

                            if (!string.IsNullOrWhiteSpace(context.ContentType))
                            {
                                brokeredMessage.ContentType = context.ContentType;
                            }

                            return brokeredMessage;
                        }, 1, cb, state));
                    },
                                                 (IAsyncResult ar) =>
                    {
                        var state = (StateHolder)ar.AsyncState;
                        Interlocked.Decrement(ref _messagesInFlight);

                        try
                        {
                            state.Sender.EndSend(ar);
                            Address.LogEndSend(state.Message.MessageId);
                        }
                        finally
                        {
                            // always dispose the message; it's only good once
                            state.Message.Dispose();
                        }
                    });
                    sending.Wait();
                }
            });
        }
		// service bus best practices for performance:
		// http://msdn.microsoft.com/en-us/library/windowsazure/hh528527.aspx
		public void Send(ISendContext context)
		{
			_connectionHandler
				.Use(connection =>
					{
						// don't have too many outstanding at same time
						SpinWait.SpinUntil(() => _messagesInFlight < _settings.MaxOutstanding);

						using (var body = new MemoryStream())
						{
							context.SerializeTo(body);
							
							// the envelope is re-usable, so let's capture it in the below closure
							// as a value
							var envelope = new MessageEnvelope(body.ToArray());

							TrySendMessage(connection, () =>
								{
									var brokeredMessage = new BrokeredMessage(envelope);

									if (!string.IsNullOrWhiteSpace(context.CorrelationId))
										brokeredMessage.CorrelationId = context.CorrelationId;

									if (!string.IsNullOrWhiteSpace(context.MessageId))
										brokeredMessage.MessageId = context.MessageId;
									
									return brokeredMessage;
								}, 1);
						}
					});
		}