• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#操作消息队列

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
public class QueueManage
{
///
/// 发送对象到队列中
///
/// 队列名称,因为队列名称在一个应用中应该不改变的,所以大家最好写在配置文件中
/// 要发出去的对象
public static void SendQueue(string QueuePath,MyBase.SmsQueue sq)
{
System.Messaging.MessageQueue mqSend=new System.Messaging.MessageQueue(QueuePath,false);
EnsureQueueExists(QueuePath);
mqSend.Send(sq);
}


///
/// 检查队列,如果队列不存在,则建立
///
/// 队列名称
private static void EnsureQueueExists(string path)
{
if(!MessageQueue.Exists(path))
{
if(!MessageQueue.Exists(path))
{
MessageQueue.Create(path);
MessageQueue mqTemp=new MessageQueue(path);
mqTemp.SetPermissions("Everyone",System.Messaging.MessageQueueAccessRights.FullControl);
///不知道该给什么样的权限好,所以就给了Everone全部权限了,当然大家最好自己控制一下
}
}
}


///
/// 从队列中取出对象列表
///
/// 队列名称
public static System.Collections.ArrayList GetMessage(string QueuePath)
{
MyBase.SmsQueue sq=new MyBase.SmsQueue();
System.Messaging.MessageQueue mq=new System.Messaging.MessageQueue(QueuePath,false);
mq.Formatter=new XmlMessageFormatter(new Type[] {typeof(MyBase.SmsQueue)});
System.Messaging.Message[] arrM=mq.GetAllMessages();
mq.Close();
System.Collections.ArrayList al=new System.Collections.ArrayList();
foreach(System.Messaging.Message m in arrM)
{
sq=(TimeFound.SmsGate.Base.SmsQueue)m.Body;
al.Add(sq);
}

return al;

}

}

从以前的一个项目中摘抄出来的,大家参考一下吧。

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#.NET进行数据库备份和还原发布时间:2022-07-14
下一篇:
C#Process.Start()方法详解C#Process.Start()方法详解发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap