并行语言查询 PLINQ

1 使用AsParrallel来进行并行的查询.

 public static void ObsoleteMethods(Assembly assembly)
        {
            var query = from type in assembly.GetExportedTypes().AsParallel()

                        from method in type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)

                        let obsoleteAttrType = typeof(ObsoleteAttribute)

                        where Attribute.IsDefined(method, obsoleteAttrType)

                        orderby type.FullName

                        let obsoleteAttrObj = (ObsoleteAttribute)Attribute.GetCustomAttribute(method, obsoleteAttrType)

                        select String.Format("Type={0}
Method={1}
Message={2}
",
                        type.FullName, method.ToString(), obsoleteAttrObj.Message);
            foreach (var result in query) Console.WriteLine(result);



        }

2,可以调用AsSequential将并行的查询转换成一个线程的顺序查询

3,使用ParallelQuery<T>.ForAll对数据进行并行处理

4,可以使用AsOrdered方法保持数据项的顺序或者使用OrderBY进行排序操作,可以使用AsUnordered来重新进入不排序的处理.

以下操作符进行排序:

OrderBy

OrderByDescending

ThenBy

ThenByDescending

5,With Cancellation 方法指定可取消

6,WithDegreeOfParallelism方法指定最大线程.

7WithExecutionMode ---------传递一个ParallelExecutionMode标志 指明并行的执行方式.

8WithMergeOption---------指明多个数据处理项jinxin给合并的方式.

9.101个LINQ查询语句https://docs.microsoft.com/zh-cn/samples/dotnet/try-samples/101-linq-samples/

10,System.Threading.Timer类

原文地址:https://www.cnblogs.com/frogkiller/p/12526886.html