1, reference system.Messagiong.dll2, using system.messagiong namespace 3, create / build yourself you need! Signify exclusive queues)
string queuename = ".// private $ // testQueue"; MessageQueue q; if (MessageQueue.Exists (queuename)) {q = new System.Messaging.MessageQueue (queuename);} else {q = MessageQueue.Create (queuename) After this code is executed, it will see queues called TestQueue in the proprietary queue in the message queue. Specifically Administrative Tools -> Computer Management -> Services and Applications -> Message Queuing -> Dedicated Queues You can see messages existing in the queue 4, send messages to queues to send messages: simple messages, Directly use Q.send ("...."); manner, complex messages (such as a specific object, of course, can be serialized), using Message M = New Message (); M.Label = "MSG1"; m.body = "test body"; q.send (m); send. The message will be sent to the queue in the default XML format encoding 5. The message receives the active mode, which will synchronize the current thread MESSAGE M = Receive (); // Remove the message or Message M = peek from the queue or Message M = peek (); / / Do not delete the received message passive mode, asynchronous call mode, will not block the current thread Q.ReceiveCompleted = new receiveCompletedEventHandler (); // event q.beginReceive (); where ReceiveDevt either a static function, or must be examples of objects that belong to the access function private static void ReceivedEvt (object source, ReceiveCompletedEventArgs asyncResult) {try {MessageQueue mq = (MessageQueue) source; Message m = mq.EndReceive (asyncResult.AsyncResult); // m is an asynchronous matter The received message / / The code console.writeline ("receiving message" m.label) is inserted here.
MQ.BEGINRECEIVE (); // Receive the next event} catCH (MessageQueueException) {} return;
Related resources: MSMQ use summary (transactional, thread monitoring, file send reception and remote information interaction)