• tpl + ccr


    不是非此即彼的场景。如下混合使用CCR+TPL的代码说明问题:
    It's not an either/or scenario.You can intermix CCR and TPL code like this, here is a Parallel.For inside of a Receive delegate:

    usingSystem;
    usingSystem.Threading;
    usingSystem.Threading.Tasks;
    usingMicrosoft.Ccr.Core;
    namespaceDemo
    {
       
    publicclassProgram
       
    {
           
    publicstaticvoidMain(string[] args)
           
    {
               
    Dispatcher dispatcher =newDispatcher();
               
    DispatcherQueue taskQueue =newDispatcherQueue("Demo", dispatcher);
               
    Port<int> portInt =newPort<int>();
                portInt
    .Post(Int32.Parse(args[0]));

               
    Arbiter.Activate(
                    taskQueue
    ,
                    portInt
    .Receive(delegate(int count)
                   
    {
                       
    Parallel.For(0, count, i =>
                       
    {
                           
    Console.Write(i.ToString()+" ");
                       
    });
                   
    }
               
    ));
           
    }
       
    }
    }

  • 相关阅读:
    299. Bulls and Cows
    Canvas实现文字散粒子化
    jQuery触发a标签点击事件-为什么不跳转
    Java 理论与实践: 正确使用 Volatile 变量
    图片全屏背景 代码实例
    Canvas 唯美雨落代码实现
    开发过程中资源限制的挑战
    死锁
    如何减少并发编程中的上下文切换
    Cookie工具类
  • 原文地址:https://www.cnblogs.com/zeroone/p/3285801.html
Copyright © 2020-2023  润新知