net tpl 数据流处理 学习 11 TransformManyBlock

TransformManyBlock

TransformManyBlock 输入一个int ,返回的是一个int的枚举,用于处理流处理是枚举的情况。


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

namespace TransformManyBlockDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            TestSync();
            Console.Read();
        }
        static TransformManyBlock<int, int> tmb = new TransformManyBlock<int, int>((i) => { return new int[] { i, i + 1 }; });

        static ActionBlock<int> ab = new ActionBlock<int>((i) => Console.WriteLine(i));

        public static void TestSync()
        {
            //这个地方就是将TransformManyBlock中的多个参数依次转换成了一个参数给ActionBlock
            tmb.LinkTo(ab);

            for (int i = 0; i < 4; i++)
            {
                tmb.Post(i);
            }

            Console.WriteLine("Finished post");
        }
    }
}



作者:spike

分类: Net

创作时间:2023-06-25

更新时间:2024-12-09

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