欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Queue<T>隊列-創(chuàng)新互聯(lián)

=====================================Document.cs

10年積累的成都網(wǎng)站設計、網(wǎng)站建設、外貿(mào)網(wǎng)站建設經(jīng)驗,可以快速應對客戶對網(wǎng)站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡服務。我雖然不認識你,你也不認識我。但先網(wǎng)站制作后付款的網(wǎng)站建設流程,更有陽朔免費網(wǎng)站建設讓你可以放心的選擇與我們合作。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
    public class Document//文本類
    {
        //標題
        public string Title { get; private set; }
        //內容
        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("標題:{0};內容:{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//文本操作類
    {
        Queue<Document> doc = new Queue<Document>();
        //向隊列中添加元素
        public void AddDocument(Document d)
        {
            lock (this)//同步操作
                doc.Enqueue(d);
        }
        //讀取頭元素,并刪除
        public Document GetDocument()
        {
            lock (this)
                return doc.Dequeue();
        }
        //判斷隊列中有沒有元素
        public bool IsAvailableDocument
        {
            get {
                return doc.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//開啟線程讀取文檔中的元素
    {
        private DocumentManage dm;
        public ProcessDocument(DocumentManage d)
        {
            dm = d;
        }
        /// <summary>
        /// 開啟線程讀取文檔中的元素
        /// </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)//判斷隊列中有沒有元素
                {
                    Console.WriteLine(dm.GetDocument().ToString());
                }
            }
        }
    }
}

=====================================主程序

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);//開啟線程讀取文檔
            for (int i = 0; i < 10000; i++)//向隊列中添加10000個元素
            {
                Document doc = new Document(i.ToString(), i.ToString());
                dm.AddDocument(doc);
                Console.WriteLine(doc.ToString() + ".....New");
            }
            
            Console.ReadKey();
        }
    }
}

Queue<T>隊列

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

網(wǎng)站名稱:Queue&lt;T&gt;隊列-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://chinadenli.net/article44/ediee.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃網(wǎng)站營銷網(wǎng)站制作定制網(wǎng)站App開發(fā)域名注冊

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)