Using MSMQ with C#

First add the MSMQ component to your windows installation. Go to Add Remove programs; Add Windows Components; Select Aplication Server; press Details and check Message Queuing

Press Ok; press Finish

Configure the Message and Queing service to restart when errors occur.

  1. Go to “Start -> Administrative tools -> Computer Management”.
  2. Expand “Services and Applications”.
  3. Sselect “Services”.
  4. Select “Message Queuing”; right click and select “Properties”.
  5. Select the “Recovery tab”.
  6. Select “Restart the Service” for first, second and subsequent failures.


Create a new C# Forms project / solution with Visual Studio 2008. Add a reference to the System.Messaging .NET dll.

Add two Forms to the project. Place in the constructor of Form1 the following code:
[sourcecode language=”csharp”]
//Q Creation

if(MessageQueue.Exists(@".Private$MyQueue"))
mq = new System.Messaging.MessageQueue(@".Private$MyQueue");
else
mq = MessageQueue.Create(@".Private$MyQueue");
Queue2 q2 = new Queue2();
q2.Show();
[/sourcecode]

Share

Leave a Reply

Your email address will not be published.