Matchcollection Parallel.Foreach

本文关键字:Foreach Parallel Matchcollection | 更新日期: 2023-09-27 18:35:30

我正在尝试为匹配集合创建一个 Parallel.Foreach 循环。它在我建造的刮板中。我只需要知道在 Parallel.Foreach 中放什么

MatchCollection m = Regex.Matches(htmlcon, matchlink, RegexOptions.Singleline);
                Parallel.ForEach(WHAT DO I PUT HERE? =>
                {
                        Get(match.Groups[1].Value, false);
                        Match fname = Regex.Match(htmlcon, @"<span class=""given-name"(.*?)</span>", RegexOptions.Singleline);
                        Match lname = Regex.Match(htmlcon, @"span class=""family-name"">(.*?)</span>", RegexOptions.Singleline);
                        firstname = fname.Groups[1].Value;
                        lastname = lname.Groups[1].Value;
                        sw.WriteLine(firstname + "," + lastname);
                        sw.Flush();
                }):

我试过了:

Parallel.ForEach<MatchCollection>(m,match  =>

但没有运气!

提前感谢! :)

Matchcollection Parallel.Foreach

这是因为Parallel.ForEach期待一个通用IEnumerable,而MatchCollection只实现了非泛型的。

试试这个:

Parallel.ForEach(
    m.OfType<Match>(),
    (match) =>
    {
    );