MessageQueue

复制代码
            MessageQueue myQueue = new MessageQueue(".\\private$\\myQueue");
            try
            {
                Message myMessage = new Message();
                myMessage.Body = "消息内容";
                myMessage.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) });
                //发送消息到队列中
                myQueue.Send(myMessage);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }
            Message myMessage2 = new Message();


            myMessage2 = myQueue.Receive();
            myMessage2.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(string) });
            string context = (string)myMessage2.Body; //获取消息的内容
            Console.WriteLine("消息内容为:" + context);
            Console.ReadKey();
复制代码

 

posted @   code_dream  阅读(155)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示