【问题标题】:Linq datatable does not contain the definition of AsParallel C#?Linq 数据表中不包含 AsParallel C# 的定义?
【发布时间】:2018-03-03 11:13:12
【问题描述】:

我收到错误“数据表不包含 AsParallel 的定义 在我的 Linq 查询中。请告诉我如何解决我做错的事情。

var results = from myRow in dtTaskandBugs.AsParallel()
                          select myRow;
            results.ForAll(async r =>
            {
                Task<int> storyProcessing = GetStoryid(r["Id"]);
                Task<int> fidProcessing = Fidname(r["Storyid"]);
                Task<string> featureProcessing = r["FeatureID"].ToString() == "0" ? Task.FromResult("Anonymous") : fname(r["FeatureID"]);
                r["Storyid"] = await storyProcessing;
                r["FeatureID"] = await fidProcessing;
                r["FeatureName"] = await featureProcessing;
            });

【问题讨论】:

标签: c# multithreading linq async-await plinq


【解决方案1】:

从我看到的here 看来,AsParallel 不是DataTable 类的扩展。您可能希望通过AsEnumerable 方法,然后根据需要进行并行化。

var results = from myRow in dt.TaskandBugs.AsEnumerable().AsParallel() select myRow;
results.ForAll(async r => ...

看看这是否不能解决你的问题。

【讨论】:

  • 对不好 (XY) 问题的直接正确解决方案。
  • @HenkHolterman 我确实对此感到担忧,现在我意识到我写的是“按需并行”,而不是我认为的如果你需要的话。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-30
  • 2019-04-15
  • 1970-01-01
  • 1970-01-01
  • 2013-07-09
  • 2021-11-28
  • 1970-01-01
相关资源
最近更新 更多