Microsoft's CCR vs Task Parallel Library

后端 未结 2 1952
耶瑟儿~
耶瑟儿~ 2021-01-01 00:37

Microsoft has at least two different approches to improved support for concurrent operations.

1) Is the Concurrency Coordination Runtime (CCR) which is part of Micro

2条回答
  •  攒了一身酷
    2021-01-01 01:05

    It's not an either/or scenario. The CCR is a library that supports certain programming patterns. You can intermix CCR and TPL code like this, here is a Parallel.For inside of a Receive delegate:

    using System;
    using System.Threading;
    using System.Threading.Tasks;
    using Microsoft.Ccr.Core;
    
    namespace Demo
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                Dispatcher dispatcher = new Dispatcher();
                DispatcherQueue taskQueue = new DispatcherQueue("Demo", dispatcher);
                Port portInt = new Port();
                portInt.Post(Int32.Parse(args[0]));
    
                Arbiter.Activate(
                    taskQueue,
                    portInt.Receive(delegate(int count)
                    {
                        Parallel.For(0, count, i =>
                        {
                            Console.Write(i.ToString() + " ");
                        });
                    }
                ));
            }
        }
    }
    

提交回复
热议问题