Create a queue and write the data
In the read out
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.messaging;usingSystem.Text;usingSystem.Threading.Tasks;namespaceQueue {classProgram {Static voidMain (string[] args) { //Send to queue//determine if this queue exists (if it is created or does not exist, the new queue will be an error) if(! Messagequeue.exists (". \\Private$\\MQDemo")) {//creates a queue at the specified locationMessageQueue Mynewprivatequeue =Messagequeue.create (". \\Private$\\TestPQueue"); } MessageQueue mqueue=NewMessageQueue (". \\private$\\MQDemo"); //create an entity for a messageSystem.Messaging.Message MSG =NewSystem.Messaging.Message (); //Assigning a value to the entity of a messageMsg.body ="QQQQQQQQQ"; Msg.formatter=NewSystem.Messaging.XmlMessageFormatter (NewType[] {typeof(string) }); //Send to Message queuemqueue.send (MSG); //-------------------------------------------------------- //reads data from the specified queue//Link this queueMessageQueue MQueue22 =NewMessageQueue (". \\private$\\MQDemo"); //get the first piece of data in the queue (the data pops up and disappears when it pops up)System.Messaging.Message Msg22 =mqueue22.receive (); //Deserialization of the messageMsg22.formatter =NewSystem.Messaging.XmlMessageFormatter (NewType[] {typeof(string) }); Console.WriteLine (Msg22.Body.ToString ()); ///MessageQueue queues can be cross-process, so the above code can be placed in two general handlers respectively///one to read///a fetchConsole.ReadLine (); } }}
MessageQueue a simple Create and read