/// <summary> /// Recieves the message async. /// </summary> protected void ReceiveMessageAsync() { SqlDataReader reader = null; while (!_isStop) { try { reader = _sqlQueueHelper.ReceiveMessage(true, Convert.ToInt32(_configuration.timeoutInSeconds.Name), true, _configuration.queue.Name, _connection); while (reader.Read()) { byte[] messageBytes = (byte[])reader.GetValue(13); String messageText = ASCIIEncoding.ASCII.GetString(messageBytes); if (!string.IsNullOrEmpty(messageText)) { IMessageEnvelope envelope = null; try { envelope = _serializer.DeserializeEnvelope(messageText); _logger.LogAdapterSuccess(envelope, "Message Received:" + envelope.MessageUID, this.GetType()); if (envelope != null) { OnMessage(envelope); } } catch (System.Exception ex) { _logger.LogAdapterFailure(envelope, ex.Message, ex, this.GetType()); } } } } catch (System.Exception ex) { _logger.LogError(ex.Message, ex); if (_connection.State == ConnectionState.Closed) { _connection.Open(); } Thread.Sleep(2000); } finally { if (reader != null) { reader.Close(); } Thread.Sleep(100); } } }