Matchcollection Parallel.Foreach [英] Matchcollection Parallel.Foreach

查看:557
本文介绍了Matchcollection Parallel.Foreach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创造一个matchcollection循环Parallel.Foreach。
它在刮板我建。
我只需要知道要放什么东西在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();

                }):

我试过:

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

但没有运气!

在此先感谢!:)

推荐答案

这是因为 Parallel.ForEach 期待一个普通的的IEnumerable MatchCollection 仅实现非通用有一个

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

试试这个:

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

这篇关于Matchcollection Parallel.Foreach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆