AsParallel 用法

http://www.cnblogs.com/leslies2/archive/2012/02/08/2320914.html

AsParallel

通常想要实现并行查询,只需向数据源添加 AsParallel 查询操作即可。

复制代码
 1     class Program
2 {
3 static void Main(string[] args)
4 {
5 var personList=GetPersonList().AsParallel()
6 .Where(x=>x.Age>30);
7 Console.ReadKey();
8 }
9
10 //模拟源数据
11 static IList<Person> GetPersonList()
12 {
13 var personList = new List<Person>();
14
15 var person1 = new Person();
16 person1.ID = 1;
17 person1.Name = "Leslie";
18 person1.Age = 30;
19 personList.Add(person1);
20 ...........
21 return personList;
22 }
23 }

阿华说List会有问题  建议用
ConcurrentBag<object> 要用这个集合来接收并发数据 AsParallel().ForEach(o=>bag.add(o))
感谢阿华孜孜不倦的回答我的每个问题
原文地址:https://www.cnblogs.com/zcm123/p/3148368.html