コード例 #1
0
        /// <summary>
        /// Returns the number of messages in the queue.
        /// </summary>
        /// <returns></returns>
        public static int GetNumberOfPendingMessages(string queueName)
        {
            var q = new MessageQueue(getFullPath(queueName));

            var    qMgmt      = new MSMQ.MSMQManagementClass();
            object machine    = Environment.MachineName;
            var    missing    = Type.Missing;
            object formatName = q.FormatName;

            qMgmt.Init(ref machine, ref missing, ref formatName);
            return(qMgmt.MessageCount);
        }
コード例 #2
0
        private static void CheckNumberOfMessages(object state)
        {
            timer.Change(int.MaxValue, int.MaxValue);

            Stopwatch watch = new Stopwatch();

            watch.Start();

            List <ManagedEndpoint> myList;

            lock (typeof(Manager))
                myList = new List <ManagedEndpoint>(endpoints);

            foreach (ManagedEndpoint endpoint in myList)
            {
                MSMQ.MSMQManagementClass qMgmt = new MSMQ.MSMQManagementClass();
                object machine    = Type.Missing;
                object missing    = Type.Missing;
                object formatName = "DIRECT=OS:" + Environment.MachineName + "\\private$\\" + endpoint.Queue;

                try
                {
                    qMgmt.Init(ref machine, ref missing, ref formatName);
                    endpoint.SetNumberOfMessages(qMgmt.MessageCount);

                    MessageQueue q = new MessageQueue("FormatName:" + formatName as string);

                    MessagePropertyFilter mpf = new MessagePropertyFilter();
                    mpf.SetAll();

                    q.MessageReadPropertyFilter = mpf;

                    Message m = q.Peek();
                    if (m != null)
                    {
                        endpoint.AgeOfOldestMessage = DateTime.Now - m.SentTime;
                    }
                }
                catch
                {
                    //intentionally swallow bad endpoints
                }
            }

            watch.Stop();

            long due = refreshInterval * 1000 - watch.ElapsedMilliseconds;

            due = (due < 0 ? 0 : due);

            timer.Change(due, refreshInterval * 1000);
        }
コード例 #3
0
ファイル: Manager.cs プロジェクト: vimaire/NServiceBus_2.0
        private static void CheckNumberOfMessages(object state)
        {
            timer.Change(int.MaxValue, int.MaxValue);

            Stopwatch watch = new Stopwatch();
            watch.Start();

            List<ManagedEndpoint> myList;

            lock(typeof(Manager))
                myList = new List<ManagedEndpoint>(endpoints);

            foreach(ManagedEndpoint endpoint in myList)
            {
                MSMQ.MSMQManagementClass qMgmt = new MSMQ.MSMQManagementClass();
                object machine = Type.Missing;
                object missing = Type.Missing;
                object formatName = "DIRECT=OS:" + Environment.MachineName + "\\private$\\" + endpoint.Queue;

                try
                {
                    qMgmt.Init(ref machine, ref missing, ref formatName);
                    endpoint.SetNumberOfMessages(qMgmt.MessageCount);

                    MessageQueue q = new MessageQueue("FormatName:" + formatName as string);

                    MessagePropertyFilter mpf = new MessagePropertyFilter();
                    mpf.SetAll();

                    q.MessageReadPropertyFilter = mpf;

                    Message m = q.Peek();
                    if (m != null)
                        endpoint.AgeOfOldestMessage = DateTime.Now - m.SentTime;
                }
                catch
                {
                    //intentionally swallow bad endpoints
                }
            }

            watch.Stop();

            long due = refreshInterval*1000 - watch.ElapsedMilliseconds;
            due = (due < 0 ? 0 : due);

            timer.Change(due, refreshInterval*1000);
        }
コード例 #4
0
        /// <summary>
        /// Returns the number of messages in the queue.
        /// </summary>
        /// <returns></returns>
        public static int GetNumberOfPendingMessages(string queueName)
        {
            var q = new MessageQueue(getFullPath(queueName));

            var qMgmt = new MSMQ.MSMQManagementClass();
            object machine = Environment.MachineName;
            var missing = Type.Missing;
            object formatName = q.FormatName;

            qMgmt.Init(ref machine, ref missing, ref formatName);
            return qMgmt.MessageCount;
        }