using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Collections;using System.Collections.Concurrent;using System.Threading;namespace ConsoleApplication5{    class Program    {        static void Main(string[] args)        {            //****************************【ConcurrentQueue
】(先进先出)*************************************            ConcurrentQueue
 cq = new ConcurrentQueue
();            for (int i = 0; i < 10; i++)            {                cq.Enqueue(i);//将元素添加到结尾处            }            int cq_result;            cq.TryDequeue(out cq_result);//尝试移除开始处的元素,成功返回true            cq.TryPeek(out cq_result);//访问开始处的元素,不移除            //****************************【ConcurrentQueue
】(先进后出)*************************************            ConcurrentStack
 cs = new ConcurrentStack
();            for (int i = 0; i < 10; i++)            {                cs.Push(i);//将元素插入到顶部            }            int cs_result;            cs.TryPop(out cs_result);//弹出 并返回顶部元素            //****************************【ConcurrentQueue
】*************************************            ConcurrentBag
 cb = new ConcurrentBag
();            for (int i = 0; i < 10; i++)            {                cb.Add(i);//添加元素            }            int cb_result;            cb.TryTake(out cb_result);//移除并返回元素            //****************************【ConcurrentQueue
】*************************************            ConcurrentDictionary
 cd = new ConcurrentDictionary
();            cd.TryAdd("a", "曹操");            cd.TryAdd("b", "关羽");//添加键值            string cd_result;            cd.TryGetValue("a", out cd_result);//获取该键对应的值            Console.WriteLine(cd.TryUpdate("a", "刘备", "曹操"));//指定键的值与第三个参数比较,相同则把第二个参数赋值给该键            string del_result;            cd.TryRemove("a", out del_result);//删除并返回该键对应的值            //****************************【BlockingCollection
】*************************************            BlockingCollection
 bc = new BlockingCollection
(cb);            bc.Add(1);//添加            foreach (var item in bc)            {                //Console.WriteLine(item+","+bc.Take());//查看            }            //****************************【并行循环Parallel.For, Parallel.ForEach,Parallel.Invoke】*************************************            //----------------------------------Parallel.For            Parallel.For(0, 30, (r, s) =>            {                // 当某一个循环单元的数大于5,                // 则跳出当前执行单元,等待其他执行单元结束                // 所有执行单元结束后退出Parallel.For的执行                if (r > 5)                {                    Console.WriteLine("a:" + r);                    s.Break();//跳出当前单元                }                Console.WriteLine("b:" + r);            });            //----------------------------------Parallel.ForEach            Parallel.ForEach(new int[] { 1, 2, 3, 4 }, (r, s) => {                Console.WriteLine(r);                s.Stop();//停止,并推出Parallel.ForEach            });            //----------------------------------Parallel.Invoke            Parallel.Invoke(() => Console.WriteLine(123) ,()=>Console.WriteLine(321));//并行执行多个委托            Console.ReadKey();        }    }}