110,499
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
MessageQueue queue = new MessageQueue();
if (!MessageQueue.Exists(".\\private$\\BookShopOrders"))
{
MessageQueue.Create(".\\private$\\BookShopOrders");
}
queue.Path = ".\\private$\\BookShopOrders";
queue.Send(TextBox1.Text,MessageQueueTransactionType.Single);
Label2.Text = "ok";
}
protected void Button2_Click(object sender, EventArgs e)
{
string[] types = { "System.String"};
MessageQueue queue = new MessageQueue();
queue.Formatter = new XmlMessageFormatter(types);
queue.Path = ".\\private$\\BookShopOrders";
Message message = queue.Receive();
Label1.Text = (string)message.Body;
}
Label2.Text = "ok";
显示出来了using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Messaging;
namespace WindowsApplication36
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
void button1_Click(object sender, EventArgs e)
{
MessageQueue queue;
if (!MessageQueue.Exists(".\\private$\\BookShopOrders"))
queue = MessageQueue.Create(".\\private$\\BookShopOrders");
else
queue = new MessageQueue(".\\private$\\BookShopOrders");
queue.Send(TextBox1.Text);
queue.Close();
Label2.Text = "ok";
}
void button2_Click(object sender, EventArgs e)
{
MessageQueue queue = new MessageQueue(".\\private$\\BookShopOrders");
queue.Formatter = new XmlMessageFormatter(new String[] { "System.String"});
System.Messaging.Message message = queue.Receive();
Label1.Text = Convert.ToString(message.Body);
queue.Close();
}
}
}