27.7 并行语言集成查询(PLinq)
Posted kikyoqiang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了27.7 并行语言集成查询(PLinq)相关的知识,希望对你有一定的参考价值。
static void Main() { ObsoleteMethods(Assembly.Load("mscorlib.dll")); Console.ReadKey(); } private static void ObsoleteMethods(Assembly assembly) { var query = from type in assembly.GetExportedTypes().AsParallel() from method in type.GetMethods(BindingFlags.Public | BindingFlags.Static | 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} Mehthod={1} Message={2} ", type.FullName, method, obsoleteAttrObj.Message); foreach (var item in query) Console.WriteLine(item); //query.ForAll(a => Console.WriteLine(a)); //让多个线程同时调用Console反而损害性能,因为Console在内部进行线程同步 //query.Distinct().AsOrdered(); //query.OrderBy(a => a.Length).AsUnordered(); //query.WithExecutionMode(ParallelExecutionMode.ForceParallelism); //query.WithMergeOptions(ParallelMergeOptions.AutoBuffered); }
以上是关于27.7 并行语言集成查询(PLinq)的主要内容,如果未能解决你的问题,请参考以下文章
何时使用 Parallel.ForEach,何时使用 PLINQ