Steven

Steven

  • NA
  • 4
  • 0

A Question About MSMQ(Microsoft Message Queue) in .net 2.0

Feb 23 2009 4:46 AM

When the code below executes,the btnSendMessage_Click method(Send Message) can complete normally.
But the btnReceiveMessage_Click method blocks at 'queue.Receive();' without any exception.Why can't
receive message?Do I need to configure my OS(Windows XP) yet ?
Any help will be appreciated!

// Send Message
private void btnSendMessage_Click(object sender, System.EventArgs e)
{

// Open queue
System.Messaging.MessageQueue queue =
new System.Messaging.MessageQueue(".\\Private$\\MSMQDemo");

// Create message
System.Messaging.Message message = new System.Messaging.Message();

message.Body = txtMessage.Text.Trim();

message.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] {typeof(string)});

// Put message into queue
queue.Send(message);

}



// Receive Message
private void btnReceiveMessage_Click(object sender, System.EventArgs e)
{

// Open queue
System.Messaging.MessageQueue queue =
new System.Messaging.MessageQueue(".\\Private$\\MSMQDemo");


// Receive message
System.Messaging.Message message = queue.Receive();

message.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] {typeof(string)});

txtReceiveMessage.Text = message.Body.ToString();
}

Answers (2)