简体   繁体   English

空MSMQ队列

[英]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: 我正在尝试从MSMQ队列中获取消息,当我的队列中有消息并且执行线程时,会发生我的问题,该代码在运行时正在清理队列:

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? 这意味着我要覆盖具有iten的队列,他们的问题是:如何获得以前创建的队列?

EDIT: 编辑:

I'm looking for a method like GetPrivateQueueByLabel , but I didn't found! 我正在寻找类似GetPrivateQueueByLabel的方法,但没有找到!

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. 因此,您的队列不会被以前的相同名称的队列替换,并且Microsoft不允许创建具有相同名称的其他队列,因此,如果已经存在具有相同名称的队列,则该队列已被使用,否则会创建新队列。 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) 另外,根据您的EDIT,除了搜索GetPrivateQueueByLabel方法外,您还可以使用以下代码片段,这些代码片段返回计算机(或您提供的计算机名称)中所有私有队列的数组

using System.Net;
using System.Messaging;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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