コード例 #1
0
        private string DoReceive(int timeoutMilliseconds)
        {
            string message_body = null;

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

                    reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        if (!reader.IsDBNull(0))
                        {
                            message_body = (string)reader[0];
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    if (reader != null)
                    {
                        if (reader.HasRows)
                        {
                            command.Cancel();
                        }
                        reader.Dispose();
                    }
                    if (command != null)
                    {
                        command.Dispose();
                    }
                }
            }
            return(message_body);
        }