예제 #1
0
        private IList <string> DoReceive(int numberOfMessages, int timeoutMilliseconds)
        {
            List <string> messages = new List <string>();

            {
                SqlCommand    command = null;
                SqlDataReader reader  = null;
                try
                {
                    command             = _connection.CreateCommand();
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.ReceiveListOfMessagesScript(QueueName, numberOfMessages, timeoutMilliseconds);
                    command.Transaction = _transaction;

                    reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        // 0 - dialog_handle : uniqueidentifier
                        // 1 - message_type  : nvarchar(256)
                        if (!reader.IsDBNull(2))
                        {
                            messages.Add(reader.GetString(2)); // message_body
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    if (reader != null)
                    {
                        if (reader.HasRows)
                        {
                            command.Cancel();
                        }
                        reader.Dispose();
                    }
                    if (command != null)
                    {
                        command.Dispose();
                    }
                }
            }
            return(messages);
        }