zoukankan      html  css  js  c++  java
  • 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;

    }

    }

    从以前的一个项目中摘抄出来的,大家参考一下吧。
  • 相关阅读:
    网页挂马实验
    基于内核网络过滤实验
    基与内核的键盘记录实验
    网络蠕虫病毒代码分析
    脚本病毒编写实验
    病毒查找与清除实验
    木马分析(植入分析)实验
    木马分析(控制分析)实验
    木马分析(隐藏分析)实验
    移动存储型病毒分析实验
  • 原文地址:https://www.cnblogs.com/NoRoad/p/1743187.html
Copyright © 2011-2022 走看看