1个回答
展开全部
给你一个小例子,如果你有点基础,应该能触类旁通。
using System.Messaging;
// 建一个类
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
//写入消息部分
Person p = new Person()
{
FirstName = "Bruce",
LastName = "Lee"
};
System.Messaging.Message msg = new System.Messaging.Message();
msg.Body = p;
MessageQueue msgQ =new MessageQueue(".\\Private$\\TestQueue");
msgQ.Send(msg);
//读出消息部分
MessageQueue msgQ = new MessageQueue(".\\Private$\\TestQueue");
msgQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(Person) });
var message = (Person)msgQ.Receive().Body;
Console.WriteLine("FirstName: " + message.FirstName + ", LastName: " + message.LastName);
Console.WriteLine("Message received ......");
更多追问追答
追问
提示缺少引用,导入哪个
追答
using System.Messaging;
引用这个,偶不是写了嘛。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询