コード例 #1
0
        /// <summary>
        /// 启动消息侦程序线程
        /// </summary>
        private void Start(MessageListener listener)
        {
            ThreadPool.STPStartInfo stp = new ThreadPool.STPStartInfo();
            stp.MaxStackSize     = MaxThreads;
            stp.MaxWorkerThreads = MaxThreads;
            ThreadPool.SmartThreadPool smartThreadpool = new ThreadPool.SmartThreadPool(stp);

            while (true)
            {
                MQMessage message = null;
                if (messageQueue.QueueConfig.isTransactional)
                {
                    MessageQueueTransaction tran = new MessageQueueTransaction();
                    message = new MQMessage(tran);
                    message.Begin();
                    message.messageContent = messageQueue.Receive(tran).Body.ToString();
                }
                else
                {
                    message = new MQMessage(null);
                    message.messageContent = messageQueue.Receive().Body.ToString();
                }
                System.Threading.Interlocked.Increment(ref Counter);
                while (Counter >= MaxThreads)
                {
                    System.Threading.Thread.Sleep(100);
                }
                smartThreadpool.QueueWorkItem(CallBack, message);
            }
        }
コード例 #2
0
        /// <summary>
        /// 启动消息侦程序线程
        /// </summary>
        private void Start(MessageListener listener)
        {
            ThreadPool.STPStartInfo stp = new ThreadPool.STPStartInfo();
            stp.MaxStackSize = MaxThreads;
            stp.MaxWorkerThreads = MaxThreads;
            ThreadPool.SmartThreadPool smartThreadpool = new ThreadPool.SmartThreadPool(stp);

            while (true)
            {
                MQMessage message = null;
                if (messageQueue.QueueConfig.isTransactional)
                {
                    MessageQueueTransaction tran = new MessageQueueTransaction();
                    message = new MQMessage(tran);
                    message.Begin();
                    message.messageContent = messageQueue.Receive(tran).Body.ToString();
                }
                else
                {
                    message = new MQMessage(null);
                    message.messageContent = messageQueue.Receive().Body.ToString();
                }
                System.Threading.Interlocked.Increment(ref Counter);
                while (Counter >= MaxThreads)
                {
                    System.Threading.Thread.Sleep(100);
                }
                smartThreadpool.QueueWorkItem(CallBack, message);
            }
        }