标签:
给你一个小例子,如果你有点基础,应该能触类旁通。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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;
引用这个,偶不是写了嘛。
写了,还是错。。。。提示不存在Messaging
你加引用啊,右击你的项目,加入引用(add reference...),然后选Framework 下的System.Messaging,再加不了就网上找教程,如何加dll引用。
标签:
原文地址:http://www.cnblogs.com/aiqingqing/p/4414033.html