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();
}
StevenPosted Feb 23, 2009, 8:21 AM
Hi,Sateesh Kumar
Thank you for so quick reply.
To my surprise,when I use the Computer Management tool in Windows XP,the message sent doesn't exist in the queue.
But the process of sending message doesn't result in an exception!Why,why?
Sateesh ArvetiPosted Feb 23, 2009, 7:10 AM
Hi,
Receive method gets a message from the queue,if exists else it waits for a message to appear .So it will be blocked,if no message exists in the Queue.You can set Timeout for Message Waiting.