首先安装消息队列MSMQ,在“计算机管理-服务和应用程序-消息队列-专用队列”中新建列队名称Demo:

     static void SendAndReceiveMsg()
        {             
            MessageQueue mq =new MessageQueue();             
            mq.Path = @".\Private$\Demo";          
            //构造消息            
            Message msg =new Message();        
            msg.Body ="Hello MessageQueue";
            //向队列发送消息       
            mq.Send(msg);
            //读取队列中的所有消息         
            Message[] msgs = mq.GetAllMessages();;
            foreach (Message m in msgs)           
            {
                m.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(string) });
                Console.WriteLine(m.Body.ToString());
            }
            //清除队列中的所有消息  
            mq.Purge();
        }     

 

相关文章:

  • 2022-12-23
  • 2021-10-23
  • 2022-01-30
  • 2022-12-23
  • 2021-04-25
  • 2021-12-13
  • 2022-01-23
猜你喜欢
  • 2021-10-25
  • 2021-06-03
  • 2021-07-25
  • 2021-10-04
相关资源
相似解决方案