简体   繁体   中英

Empty MSMQ queue

I'm trying to get messages from a MSMQ queue, my problem occurs when I have messages in my queue and I execute my thread, it was cleaning the queue when this code runs:

queue = new MessageQueue(queueName);

It means that I'm overriding the queue that had itens, them my question is: how can I get my previously created queue?

EDIT:

I'm looking for a method like GetPrivateQueueByLabel , but I didn't found!

Use Following Code in place of your code

//queue = new MessageQueue();

if(queue.Path==null)
{
     queue.Path = queueName;
}
//now use queue object for further process

so that your queue is not replace by previous queue with same name and Microsoft will not allow to create different queue with same name so if queue with same name is already present then it has been used else new queue is create. Also as per your EDIT your searching for GetPrivateQueueByLabel Method apart from that you can use following code snippet which return array of all private Queue in your Machine (or machine Name which you Provide)

using System.Net;
using System.Messaging;

MessageQueue[] privatequeuelist = MessageQueue.GetPrivateQueuesByMachine(Dns.GetHostName());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM