首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

网络采集工具的页面刷新有关问题

2012-01-14 
网络采集工具的页面刷新问题我做了一个小软件,是网络采集方面的。大家可以从这个地址下载试用http://u4.sh.

网络采集工具的页面刷新问题
我做了一个小软件,是网络采集方面的。大家可以从这个地址下载试用http://u4.sh.com/ContentPane.aspx?down=ok&filename=Release.rar&filepath=careast%2fRelease.rar&GUID=BF73C745F0C8D689

在程序中我是如下处理的:在页面中找到一条记录,就在datagridview中加入这条记录。如果当前页面找完了,则把这个页面的地址加入到另外一下datagridview中去。大概代码如下:

private   void   GetInfo(List <string>   _urlLst,   List <Regex>   _regRecord,   List <Regex>   _regAcptUrl)   {
                        if   (_urlLst.Count   !=   0)   {
                                urlDepth++;//网址深度
                                List <string>   nextLayerUrlLst   =   new   List <string> ();//下一层次的URL  

                                //遍历_urlLst中每一个链接
                                for   (int   i   =   0;   i   <   _urlLst.Count;   i++)   {
                                        //检查当前链接的页面有没有符合匹配规则的信息,如果有,则把匹配到的依次加入到信息集中                                        
                                       
                                        try   {
                                                //获得网页源码
                                                string   webContent   =   myUtil.GetWebContent(_urlLst[i]);

                                                //获取匹配记录
                                                string[]   tmpValue   =   new   string[_regRecord.Count   +   1];
                                                for   (int   j   =   0;   j   <   _regRecord.Count;   j++)   {
                                                        if   (_regRecord[j].IsMatch(webContent))   {
                                                                tmpValue[j]   =   _regRecord[j].Match(webContent).Groups[1].Value;
                                                        }   else   {


                                                                tmpValue[j]   =   " ";
                                                        }
                                                }
            把当前页面地址加入到数组中,使得这个数组形成像这个样子:tmpValue[0]= "aa "   tmpValue[1]= "bb "   tmpValue[2]= "http://www.163.com/... "
                                                tmpValue[_regRecord.Count]   =   _urlLst[i];
                                                把这个记录加入到datagridview中去,并在页面上显示
                                                gv_Record.Rows.Add(tmpValue);

                                                //加入完后,取得这个页面中的所有子链接,把新的满足网址标识条件的加入到nextLayerUrlLst中
                                                List <string>   tmpNextUrl   =   myUtil.GetHrefString(webContent);
                                                for   (int   j   =   0;   j   <   tmpNextUrl.Count;   j++)   {
                                                        for   (int   k   =   0;   k   <   _regAcptUrl.Count;   k++)   {
                                                                                                                                if   (_regAcptUrl[k].IsMatch(tmpNextUrl[j]))   {
                                                                        if   (nextLayerUrlLst.Contains(tmpNextUrl[j]))   {//如果已经包含当前网址
                                                                                break;


                                                                        }   else   {
                                                                                nextLayerUrlLst.Add(tmpNextUrl[j]);
                                                                                break;
                                                                        }
                                                                }
                                                        }
                                                }

                                                //把这个页面的地址加入到gv_Url中
                                                gv_Url.Rows.Add(new   string[]   {   _urlLst[i],   urlDepth.ToString()   });
                                        }   catch   (Exception   ex)   {
                                                MessageBox.Show( "发生错误: "   +   ex.Message,   "系统信息 ");
                                                return;
                                        }
                                }

                                //递归执行这个方法
                                GetInfo(nextLayerUrlLst,   _regRecord,   _regAcptUrl);
                        }
                }


这个方法是在程序中点出按钮时,开始执行的,现在在问题是我想让这个方法在后台执行,页面上数据变动我能看到,而且不影响我执行其他操作。

[解决办法]
看下先...
[解决办法]
Application.DoEvents呢?
[解决办法]
lizhizhe2000(武安候)的意思呢,要在你的程序中加入以下代码
Application.DoEvents();
加入位置是
gv_Url.Rows.Add(new string[] { _urlLst[i], urlDepth.ToString() });
的后面。关于DoEvents的意思:单线程里面如果大量计算在某些操作后面,这些操作造成的客户区可能没来得及重绘,用Application.DoEvents可以强制把消息先处理了,再进行后面的计算。


[解决办法]
帮LZ顶

热点排行