net tpl 数据流处理 学习 05 BufferBlock 先进先出


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;

namespace BufferBlockDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a BufferBlock<int> object.
            //表示一般用途的异步消息结构
            // 此类存储先进先出 (FIFO) 消息队列,此消息队列可由多个源写入或从多个目标读取。 
            // 在目标收到来自消息BufferBlock<> </> > 对象,从消息队列中移除该消息
            var bufferBlock = new BufferBlock<int>();

            // Post several messages to the block.
            for (int i = 0; i < 3; i++)
            {
                bufferBlock.Post(i);
            }

            // Receive the messages back from the block.
            for (int i = 0; i < 4; i++)
            {
                Console.WriteLine(bufferBlock.Receive());
            }

            Console.Read();
            /* Output:
               0
               1
               2
             */
        }

    }
}



作者:spike

分类: Net

创作时间:2023-06-25

更新时间:2024-12-09

联系方式放在中括号之中例如[[email protected]],回复评论在开头加上标号例如:#1