zoukankan      html  css  js  c++  java
  • PLinq Lookup ParallelQuery

    
    namespace Microshaoft
    {
        using System;
        using System.Linq;
        using System.Threading.Tasks;
        using System.Threading;
        using System.Collections.Generic;
        using System.Collections.Concurrent;
        class Program
        {
            static void Main(string[] args)
            {
                var list = new List<Employee>()
                                        {
                                            new Employee()
                                                    {
                                                        ID = 100
                                                        , Name = "Bill Gates"
                                                        , Department = "Microsoft"
                                                    }
                                            , new Employee()
                                                    {
                                                        ID = 2
                                                        , Name = "Steve Jobs"
                                                        , Department = "Apple"
                                                    }
                                            , new Employee()
                                                    {
                                                        ID = 300
                                                        , Name = "Larry Page"
                                                        , Department = "Google"
                                                    }
                                            , new Employee()
                                                    {
                                                        ID = 4
                                                        , Name = "Sergey Brin"
                                                        , Department = "Google"
                                                    }
                                            , new Employee()
                                                    {
                                                        ID = 300
                                                        , Name = "Larry Page2"
                                                        , Department = "Google"
                                                    }
                                            , new Employee()
                                                    {
                                                        ID = 4
                                                        , Name = "Microshaoft"
                                                        , Department = "Microsoft"
                                                    }
                                        };
                var groups = list.ToLookup<Employee,string>
                                                (
                                                    x =>
                                                    {
                                                        return x.Department;
                                                    }
                                                );
                groups.AsParallel().WithDegreeOfParallelism
                                            (
                                                groups.Count
                                            ).ForAll
                                                    (
                                                        (x) =>
                                                        {
                                                            Console.WriteLine("{0},{1}", Thread.CurrentThread.ManagedThreadId, x.Key);
                                                            var orderedGroup = x.OrderByDescending<Employee, int>
                                                                                (
                                                                                    (xx) =>
                                                                                    {
                                                                                        return xx.ID;
                                                                                    }
                                                                                );
                                                            //orderedGroup.AsParallel().WithDegreeOfParallelism(1).ForAll
                                                            //        (
                                                            //            (xxx) =>
                                                            //            {
                                                            //                Console.WriteLine("{0},{1}", Thread.CurrentThread.ManagedThreadId, xxx.Name);
                                                            //            }
                                                            //        );
                                                            orderedGroup.ToList().ForEach
                                                                                    (
                                                                                        (xxx) =>
                                                                                        {
                                                                                            Console.WriteLine("{0},{1}", Thread.CurrentThread.ManagedThreadId, xxx.Name);
                                                                                        }
                                                                                    );
                                                        }
                                                    );
                Console.ReadLine();
            }
            public class Employee
            {
                public int ID
                {
                    get;
                    set;
                }
                public string Name
                {
                    get;
                    set;
                }
                public string Department
                {
                    get;
                    set;
                }
                public string Gender
                {
                    get;
                    set;
                }
                public DateTime Birthday
                {
                    get;
                    set;
                }
            }
        }
    }
    
    
  • 相关阅读:
    Eclipse快捷键
    vs2010有哪些快捷键
    游戏引擎列表
    移动设备开发推荐网站(J2ME开发)
    Python入门学习资料推荐
    C#中常用的几种读取XML文件的方法
    Springboot整合RabbitMq
    JAVA获取上下行网速
    java jar 指定logback.xml、application.yaml
    在CentOS7系统安装与配置RabbitMQ
  • 原文地址:https://www.cnblogs.com/Microshaoft/p/2570395.html
Copyright © 2011-2022 走看看