Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 41,685 times

Contents

Related Categories

Get the Message - MSMQ - Receiving Messages with Events

LACanadian

Receiving Messages with Events

The technique illustrated in Receiving a Message to receive message has a significant drawback. As long as the process is waiting to receive a message, it can do nothing else. In other words, the message queue holds the process thread hostage. An alternative is to establish an MSMQEvent object that allows your application to respond to incoming messages as events that are raised through this object. The code below shows an example of how to accomplish this. Be aware that there are actually three parts to this code. The first two lines are in the General Declaration portion of the form. They are followed by the Form_Load and event procedures.

Private RequestQ As MSMQQueue
Private WithEvents RequestEvent As MSMQEvent

Private Sub Form_Load()

Dim QI As New MSMQQueueInfo

QI.PathName = "MyServer\QueueName"
Set RequestQ = QI.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE)

Set RequestEvent = New MSMQEvent
RequestQ.EnableNotification RequestEvent

End Sub

Sub RequestEvent_Arrived(ByVal Queue as Object, ByVal Cursor As Long)

Dim InQueue As MSMQQueue
Dim msg As MSMQMessage

Set InQueue = Queue
Set msg = InQueue.Receive(ReceiveTimeOut:=0)
If Not msg is Nothing Then
' Process the message
End If

InQueue.EnableNotification RequestEvent

End Sub


In this example, the EnableNotification method is used to associate an MSMQEvent object with a queue. This causes the Arrived event to be triggered whenever a message is posted to that queue. You should also notice that the EnableNotification method was called again at the bottom of the Arrived procedure. That is because EnableNotification only sets up the event for the next message.

I am the owner of a small application development consulting company that specialized in the design and implementation of Internet-based applications. While there are others who can make a web site look good, our expertise is in making the site function. This includes infrastructure design, database design and administration, software development and deployment. For the most part, we utilize Microsoft-based languages and tools. And we are skilled enough to have generated two patent applications for our clients.

Comments

  • enableNotification in MSMQ using vb.net

    Posted by shahidnoor86 on 29 Jul 2008

    I am using MSMQ-3 on my local machine. I am using enableNotification method to notify me when a message comes in the queue. But i am getting error message while using enableNotification. The messag...

  • XML sample

    Posted by mightytookDev on 08 Dec 2004

    Ummm, there's a lot of other stuff around the code that I have (which was in a VB.DLL used within ASP pages), but I tried to pull out the working code that would get to the essence of what you need. E...

  • How to send and receive an XML file in a message q

    Posted by CyberLotus on 08 Dec 2004

    Hi,

    Could you please let me know, how to send an xml file as an object to a message queue? If possible can you provide me any code snippet for this as I'm novice to this technology.

    Also, I want...

  • MSMQ

    Posted by thongfam on 21 Sep 2004

    Hi,


    I have similar error "The operation is not supported on a workgoup installation of computer" while testing MSMQ program. I am using VB6 to write the MSMQ program. Do you have any advise on h...

  • MSMQ

    Posted by gdiazzap on 25 May 2004

    I need to Know hoy many messages are in a MSMQ Queue using API, WMI or OCX component using Visual Basic
    Any Idea?

    Gabriel