我已经写了下面的linq语句。但是由于线路太多,处理需要很长的时间。我的CPU有8个内核,但由于运行单线程只使用1个内核。这个LinQ语句可以运行多线程 - 使用更多的cpu核心
所以我很想知道这个最终版本能够在多线程中运行吗?
List<string> lstAllLines = File.ReadAllLines("AllLines.txt").ToList();
List<string> lstBannedWords = File.ReadAllLines("allBaddWords.txt").
Select(s => s.ToLowerInvariant()).
Distinct().ToList();
我在问下面的问题。该线可以工作多线程?
List<string> lstFoundBannedWords = lstBannedWords.Where(s => lstAllLines.
SelectMany(ls => ls.ToLowerInvariant().Split(' ')).
Contains(s)).
Distinct().ToList();
C#5,netframework 4.5
看着[PLINQ](http://msdn.microsoft.com/zh-cn/library/dd460688.aspx)?请注意,这无法保证让任何事情都能更快运行。 –
@AdamHouldsworth还没有检查,但让我看看:) – MonsterMMORPG
http://stackoverflow.com/questions/7582591/how-to-plinq-an-existing-linq-query-with-joins([了解加速在PLINQ中](http://msdn.microsoft.com/en-us/library/dd997399.aspx))查询的代价越高,PLINQ的候选人就越好。 –