AsParallel 用法

时间:2023-03-09 08:06:15
AsParallel 用法

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

AsParallel

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

AsParallel 用法
     class Program
{
static void Main(string[] args)
{
var personList=GetPersonList().AsParallel()
.Where(x=>x.Age>);
Console.ReadKey();
} //模拟源数据
static IList<Person> GetPersonList()
{
var personList = new List<Person>(); var person1 = new Person();
person1.ID = ;
person1.Name = "Leslie";
person1.Age = ;
personList.Add(person1);
...........
return personList;
}
}

阿华说List会有问题  建议用

ConcurrentBag<object> 要用这个集合来接收并发数据 AsParallel().ForEach(o=>bag.add(o))
感谢阿华孜孜不倦的回答我的每个问题