C # simple example of Message Queue

Source: Internet
Author: User

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. messaging;

Namespace queuetest
{
Class Program
{
Static void main (string [] ARGs)
{
String Path = @ ". \ private $ \ test ";

If (messagequeue. exists (PATH ))
{
Messagequeue. Delete (PATH );
}
// Create a message queue and send it
Messagequeue msq = messagequeue. Create (PATH );
Msq. Send (8 );
Msq. Send ("Jason ");

Mathes Mm = new mathes ();
Msq. Send (mm );
Msq. Send (mm );

// Team out
(Xmlmessageformatter) msq. formatter). targettypes = new type [] {typeof (system. int32 )};
Message M1 = msq. Receive ();

Console. writeline (m1.body. tostring ());

(Xmlmessageformatter) msq. formatter). targettypes = new type [] {typeof (system. String )};
Message m2 = msq. Receive ();

Console. writeline (m2.body. tostring ());

(Xmlmessageformatter) msq. formatter). targettypes = new type [] {typeof (mathes )};
Message m3 = msq. Receive ();
Console. writeline (Mm. sumab (10, 20 ));

# Region asynchronous

(Xmlmessageformatter) msq. formatter). targettypes = new type [] {typeof (mathes )};
Msq. beginreceive (New timespan (10000), msq, new asynccallback (mysum ));

# Endregion

Console. Read ();
}

Static void mysum (iasyncresult IA)
{
Messagequeue msq = IA. asyncstate as messagequeue;

Message M4 = msq. endreceive (IA );

Mathes Mm = m4.body as mathes;

Console. writeline (Mm. sumab (25, 35 ));
}
}
Public class mathes
{
Private int A = 25;

Private string B = "35 ";

Public String B
{
Get {return B ;}
Set {B = value ;}
}

Public int
{
Get {return ;}
Set {A = value ;}
}

Public int sumab (int A, int B)
{
Return A + B;
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.