advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   TIP BANK
Browse DevX
Download the code for this article
Partners & Affiliates
advertisement
advertisement
advertisement
advertisement
 

MSMQ for .NET Developers, Part 2

Learn how to use MSMQ to send messages with complex messages types (not just strings), send MSMQ messages over HTTP, and explore several more useful queue and message properties as well as a few invaluable MSMQ tips and pitfalls. 


advertisement
art 1 of this article included an example that demonstrated how to read messages from a queue asynchronously. That example worked by first calling BeginReceive on the queue object and then setting a delegate called whenever a new message is received. The BeginReceive method call included a TimeSpan parameter that limited the time to wait for a new message to arrive in the queue to 15 seconds. Using this technique, if a message fails to arrive in the queue within the time allotted, the code calls the ReceiveCompleted delegate—in this case, raising an exception when the EndReceive method is called, signaling the application that no message was received before the timeout expired.


Here is the code used in the original example.

 ' connect to the queue
myReceiveQueue = New _
MessageQueue(".\private$\DevXTestQueue")
myReceiveQueue.Formatter = _
New XmlMessageFormatter(New Type() _
{GetType(System.String)})
' add a handler to tell MSMQ which method to call when a
' message arrives
AddHandler myReceiveQueue.ReceiveCompleted, _
AddressOf MSMQ_ReceiveCompleted
' call the asynchronous version of Receive,
' waiting no longer than 15 seconds
myReceiveQueue.BeginReceive(New TimeSpan(0, 0, 15))

It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com.
Already a member?



advertisement