c# msmq的简单操作
来源:互联网 发布:android ndk mac 下载 编辑:程序博客网 时间:2024/06/08 09:07
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Messaging;//测试msmq的功能namespace TestMQ{ class Program { /**/ /// <summary> /// 通过Create方法创建使用指定路径的新消息队列 /// </summary> /// <param name="queuePath"></param> public static void Createqueue(string queuePath) { try { if (!MessageQueue.Exists(queuePath)) { MessageQueue.Create(@".\private$\emporer"); } else { Console.WriteLine(queuePath + "已经存在!"); } } catch (MessageQueueException e) { Console.WriteLine(e.Message); } } /**/ /// <summary> /// 连接消息队列并发送消息到队列 /// </summary> public static void SendMessage() { try { //连接到本地的队列 MessageQueue myQueue = new MessageQueue(@".\private$\emporer"); Message myMessage = new Message(); myMessage.Body = "22222222222222222"; myMessage.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) }); //发送消息到队列中 myQueue.Send(myMessage); } catch (ArgumentException e) { Console.WriteLine(e.Message); } } /**/ /// <summary> /// 连接消息队列并从队列中接收消息 /// </summary> public static void ReceiveMessage() { //连接到本地队列 MessageQueue myQueue = new MessageQueue(".\\private$\\emporer"); myQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(string) }); try { //从队列中接收消息 Message myMessage = myQueue.Receive(); string context = (string)myMessage.Body; //获取消息的内容 Console.WriteLine("消息内容为:" + context); } catch (MessageQueueException e) { Console.WriteLine(e.Message); } catch (InvalidCastException e) { Console.WriteLine(e.Message); } } /**/ /// <summary> /// 清空指定队列的消息 /// </summary> public static void ClearMessage() { MessageQueue myQueue = new MessageQueue(".\\private$\\emporer"); myQueue.Purge(); } static void Main(string[] args) { Program.SendMessage(); Program.ReceiveMessage(); Console.ReadLine(); } }}
0 0
- c# msmq的简单操作
- C# 操作 MSMQ
- C# MSMQ 原理简单介绍
- MSMQ的简单介绍
- MSMQ的简单介绍
- MSMQ的简单应用
- 简单的msmq例子
- 用C#实现的MSMQ
- 用C#实现的MSMQ
- 用C#实现的MSMQ
- MSMQ的简单介绍(收藏)
- MSMQ的简单包装类
- 简单的c#操作
- C# Excel简单的操作
- C#矩阵的简单操作
- C# 二进制文件操作 简单的文件操作
- 一个简单的MSMQ的发送和接收类
- MSMQ的VB操作代码/步骤(简化版)
- 2014-03-11周二工作记录
- PL/SQL启动报错:Control 'dxDockBrowserPanel' has no parent window分析及解决
- KindEditor英文或数字环境下无需设置自动换行!!!!
- Android游戏开发 study 4-5
- 进程与线程的区别(转)
- c# msmq的简单操作
- 输出包含共同元素的变量值
- Hibernate错误写法
- PHP 引用文件
- java final的用法
- VS2013服务器资源管理器添加Mysql数据源
- 多线程编程练习:使用变量控制多线程调用顺序
- OnCtrlColor,OnDrawItem,DrawItem,OnPaint之间关系
- ado.net视频教程-实战开发CRM企业客户管理系统