Queue <t> queue

Source: Internet
Author: User

======================================================== Document. CS

Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; namespace consoleapplication2 {public class document // text class {// Title Public String title {Get; private set ;}// content Public String content {Get; private set ;} public document (String title, string content) {This. title = title; this. content = content;} public override string tostring () {return string. format ("title: {0}; content: {1};", this. title, this. content );}}}

======================================================== Documentmanage. CS

Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; using system. collections; namespace consoleapplication2 {public class documentmanage // text operation class {queue <document> Doc = new queue <document> (); // Add the public void adddocument (document D) {lock (this) element to the queue // synchronization operation Doc. enqueue (d);} // read the Header element and delete the public document getdocument () {lock (this) return Doc. dequeue ();} // determines whether the public bool isavailabledocument {get {return Doc is an element in the queue. count> 0 ;}}}}

====================================================== Processdocument. CS

Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; using system. threading; namespace consoleapplication2 {public class processdocument // enable the thread to read the elements in the document {private documentmanage DM; Public processdocument (documentmanage d) {dm = D ;} /// <summary> /// enable the thread to read the elements in the document /// </Summary> /// <Param name = "D"> </param> Public static void start (documentmanage D) {New thread (New processdocument (d ). run ). start ();} private void run () {While (true) {If (DM. isavailabledocument) // checks whether the queue has any elements {console. writeline (DM. getdocument (). tostring ());}}}}}

============================================ Main program

Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; namespace consoleapplication2 {class program {static void main (string [] ARGs) {documentmanage dm = new documentmanage (); processdocument. start (DM); // enable the thread to read the document for (INT I = 0; I <10000; I ++) // Add 10000 elements to the queue {document DOC = new document (I. tostring (), I. tostring (); DM. adddocument (DOC); console. writeline (Doc. tostring () + "..... new ");} console. readkey ();}}}

 

650) This. width = 650; "style =" width: 736px; Height: 285px; "Title =" spximage51.jpg "src =" http://s3.51cto.com/wyfs02/M02/47/81/wKioL1P7bGbBX1wwAAInY2WYhJU205.jpg "width =" 780 "Height =" 279 "alt =" wkiol1p7bgbbx1wwaainy2wyhju205.jpg "/>

This article from the "programmer's home" blog, please be sure to keep this source http://962410314.blog.51cto.com/7563109/1544977

Queue <t> queue

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.