日期:2014-05-18 浏览次数:21430 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Messaging;
namespace messagedemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void send_Click(object sender, EventArgs e)
        {
            System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(".\\Private$\\MSMQDemo");
            System.Messaging.Message message = new System.Messaging.Message();
            message.Body = txtMessage.Text.Trim();
            message.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(string) });
            queue.Send(message);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            System.Messaging.MessageQueue queue = new System.Messaging.MessageQueue(".\\Private$\\MSMQDemo");
            System.Messaging.Message message = queue.Receive();
            message.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(string) });
            txtReceiveMessage.Text = message.Body.ToString();
        }
    }
}