Excerpt from MSDN
Using system.med; using system.drawing; using system.io;
Namespace myproject {
///
// ******************************************************** ** // provides an entry point info the application. ///////// a Queue. // ******************** *****************************
Public static void main () {// create a new instance of the class. mynewqueue mynewqueue = new mynewqueue ();
// Create a Queue on the local computer. Createqueue (".// myqueue"); // send a message to a queue. Mynewque u.sendMessage ();
// receive a message from a queue. Mynewqueue.RecEceptage ();
Return;}
// ******************************************************** ** // Creates a new queue. // ************************************************* ***********
public static void CreateQueue (string queuePath) {try {if {MessageQueue.Create (queuePath) (MessageQueue.Exists (queuePath)!);} else {Console.WriteLine (queuePath "already exists.");}} catch (MessageQueueException e) {console.writeLine (E.MESSAGE);}}
// ******************************************************** ** // sends an image to a queue, using the binarymessageformatter. // **************************************************** **************** PUBLIC VOID SendMAG () {Try {// Create a New Bitmap. // The file must be in the / bin / debug or / bin / retail folder , or // you must give a full path to it = bitmap.fromfile ("SentImage.BMP");
// Connect to a queue on the local computer. MessageQueue myqueue = new messagequeue (".// myqueue"); message mymessage = new message (MyImage, New binaryMessageFormatter ());
// send the image to the queue. Myqueue.send (mymessage);} catch (argumentexception e) {console.writeline (E.MESSAGE);
Return;}
// ******************************************************** ** // Receives A Message Containing An Image. // ********************************************************* ************* PUBLIC VOID ReceiveMessage () {TRY {
// Connect to the a queue on the local computer. MessageQueue myqueue = new messagequeue (".// myqueue");
// set the formatter to indeicate body contacts an order. MyQueue.formatter = new binaryMessageFormatter ();
// Receive and format the message System.Messaging.Message myMessage = myQueue.Receive ();. Bitmap myImage = (Bitmap) myMessage.Body; // This will be saved in the / bin / debug or / bin / retail folder. myImage.Save ( "ReceivedImage.bmp", System.Drawing.Imaging.ImageFormat.Bmp);..} catch (MessageQueueException) {// Handle Message Queuing exceptions} // Handle invalid serialization format catch (InvalidOperationException e) {Console. WriteLine (E.MESSAGE);
Catch (IOException E) {// Handle File Access Exceptions.} // Catch Other Exceptions as Necessary.
Return;}}}}
Also pay attention, MessageQueue is a separate tool that does not install together with VS.NET. So if you want to use, pay attention to install it.