1. 程式人生 > >27.7 並行語言集成查詢(PLinq)

27.7 並行語言集成查詢(PLinq)

asp tom 同時 type 集成 多個 sde execution lin

        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} \n Mehthod={1} \n Message={2} \n ", 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)