【发布时间】:2013-05-31 13:32:15
【问题描述】:
我已经写了下面的 linq 语句。但是由于行数太多,因此需要大量时间来处理。我的 cpu 有 8 个内核,但由于运行单线程而只使用 1 个内核。
所以我想知道这个最后的语句是否可以在多线程中运行?
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,网络框架 4.5
【问题讨论】:
-
查看了PLINQ?请注意,这并不能保证让任何东西运行得更快。
-
@AdamHouldsworth 还没有检查,但让我看看 :)
-
stackoverflow.com/questions/7582591/… (Understanding Speedup in PLINQ) 查询成本越高,PLINQ 的候选者就越好。
-
哇,它开始使用 5 个内核,只需添加 1 个关键字,呵呵:我喜欢 C# ^^
-
@Chris
.AsParallel()我想。
标签: c# multithreading linq