Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matchcollection Parallel.Foreach

I'm trying to create a Parallel.Foreach loop for matchcollection. It's in a scraper I built. I just need to know what to put in the 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();

                }):

I tried:

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

but no luck!

Thanks in advance! :)

like image 530
Zbone Avatar asked Dec 10 '22 00:12

Zbone


1 Answers

That's because Parallel.ForEach is expecting a generic IEnumerable and MatchCollection only implements the non generic one.

Try this:

Parallel.ForEach(
    m.OfType<Match>(),
    (match) =>
    {
    );
like image 103
Pedro Avatar answered Dec 24 '22 15:12

Pedro