程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> asp.net(C#)下應用MSMQ收發消息

asp.net(C#)下應用MSMQ收發消息

編輯:.NET實例教程
protected void Button1_Click(object sender, EventArgs e)
        {
            MessageQueue msq;
            if (MessageQueue.Exists(@".\Private$\tests"))
            {
                msq = new MessageQueue(@".\Private$\tests");
            }
            else
            {
                msq =MessageQueue.Create(@".\Private$\tests");
            }
            BinaryWriter bw = new BinaryWriter(new MemoryStream());
            bw.Write(TextBox1.Text);
            Message msg = new Message();
            msg.BodyStream = bw.BaseStream;
            msg.Label = "Send Messages";
            msq.Send(msg);
            Label1.Text = "發送消息!";

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            MessageQueue msq;
            Message msg = new Message();
            BinaryReader br;
          &nb

$False$

sp; string msgs;
            if (MessageQueue.Exists(@".\private$\tests"))
            {
                msq = new MessageQueue(@".\private$\tests");
//說明網上很多版本寫作msq = new MessageQueue(".\\private$\tests"),運行時將出現錯誤。
            }
            else
            {
                msq = MessageQueue.Create(@".\private$\tests");
            }
            try
            {
                msg = msq.Receive(new TimeSpan(0, 0, 3));
                br = new BinaryReader(msg.BodyStream);
                msgs = new string(br.ReadChars(Convert.ToInt32(msg.BodyStream.Length)));
            }
            catch
            {
                msgs = "沒有消息!";
            }
            Label1.Text = msgs;
        } 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved