Give you a small example, if you have a bit of foundation, you should be able to comprehend by analogy.
12345678910111213141516171819202122232425262728 |
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 ......"
);
|
Ask:
Prompt for missing references, importing which
Chase Answer:
Using System.Messaging;
Quoting this, I'm not writing it.
Ask:
Written, or wrong .... Hint does not exist messaging
Chase Answer:
You add the quote Ah, right click on your project, add the reference (Add Reference ...), and then select the framework under the System.Messaging, and then add to the online tutorial, how to add DLL reference.
C # queues