using System;
using System.Messaging;
[Serializable]
class MyMessage {
private string data;
public MyMessage(string data) {
this.data = data;
}
public override string ToString() {
return data;
}
}
class Program {
static void Main(string[] args) {
try {
if (!MessageQueue.Exists(@".\Private$\MyPrivateQueue")) {
MessageQueue.Create(@".\Private$\MyPrivateQueue");
}
MessageQueue queue = new MessageQueue(@".\Private$\MyPrivateQueue");
queue.Formatter = new BinaryMessageFormatter();
queue.Send("Sample Message", "Label");
MyMessage m = new MyMessage("xxx");
queue.Send(m, "Binary Test");
} catch (MessageQueueException ex) {
Console.WriteLine(ex.Message);
}
}
}