如何检查公共MSMQ是否为空 [英] How to check if public MSMQ is empty

查看:89
本文介绍了如何检查公共MSMQ是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以检查公共MSMQ是否为空?对于私有MSMQ,这很容易:

Is there any way to check if a public MSMQ is empty? For a private MSMQ it's easy:

private bool IsQueueEmpty(string path)
        {
            bool isQueueEmpty = false;
            var myQueue = new MessageQueue(path);
            try
            {
                myQueue.Peek(new TimeSpan(0));
                isQueueEmpty = false;
            }
            catch (MessageQueueException e)
            {
                if (e.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout)
                {
                    isQueueEmpty = true;
                }
            }
            return isQueueEmpty;
        }

对于公开的MSMQ,我将如何做同样的检查?如果我尝试使用上面的代码检查公共MSMQ,则会在Peak上给我一个错误:

How would I do the same check for a public MSMQ? If I try to check a public MSMQ with the code above it gives me an error on the Peak:

System.ArgumentOutOfRangeException:长度不能小于零.

推荐答案

仅当您使用直接格式名称访问队列时,Peek方法仅在远程计算机上可用.只要您不依赖目录服务来进入队列,就应该能够使用相同的代码.

The Peek method is only available on remote machines when you use a direct format name to access the queue. You should be able to use the same code, so long as you're not relying on directory services to get you to the queue.

直接队列名称通常类似于:DIRECT=URLAddressSpecification/QueueName

Direct queue names generally look something like: DIRECT=URLAddressSpecification/QueueName

这篇关于如何检查公共MSMQ是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆