标题: C#操作消息队列
问天
元帅
Rank: 1


元帅勋章 终身成就勋章
UID 11493
精华 186
积分 34130
帖子 33347
威望 88
金币 13137
热心 2611
阅读权限 100
注册 2006-4-7
状态 离线
C#操作消息队列

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;

}

}

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


网友 问天 签名 - 网友社区 请您回个帖。谢谢
PR查询 免费域名 免费空间
顶部
[广告] 免费域名(Free Subdomain) 免费空间(Free hosting) PR查询(Google Pagerank)



当前时区 GMT+8, 现在时间是 2008-9-6 02:54
信产部ICP备案:京ICP备05066424号 北京市公安局网监备案:1101050648号

Powered by Discuz! 5.5.0
清除 Cookies - 联系我们 - 网友俱乐部 - Archiver - WAP