Eu estou tentando criar um loop Parallel.Foreach para matchcollection. Está em um raspador que eu construí. Eu só preciso saber o que colocar no 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();
}):
Eu tentei:
Parallel.ForEach<MatchCollection>(m,match =>
mas sem sorte!
Desde já, obrigado! :)
Respostas:
14 para resposta № 1Isso é porque Parallel.ForEach
está esperando um genérico IEnumerable
e MatchCollection
apenas implementa o não genérico.
Tente isto:
Parallel.ForEach(
m.OfType<Match>(),
(match) =>
{
);