htmlagilitypack在第一次运行时变慢

时间:2013-01-14 21:20:13

标签: c# winforms performance html-agility-pack

首次运行需要15秒以上......首次运行后不到1秒......我怎么能解决它?

System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();   

sw.Start();
siteKeyword = tbSearch.Text;
web.OverrideEncoding = Encoding.GetEncoding("windows-1251");
doc = web.Load(siteSearch + siteKeyword);
HtmlNodeCollection items = doc.DocumentNode.SelectNodes("//div[@class='cls1']");

int i = 0;
foreach (var item in items)
{
    lbResults.Items.Add(item.SelectSingleNode("h2/a").InnerText);
    resultsHREF.Add(item.SelectSingleNode("h2/a").Attributes["href"].Value);
    i++;
}
sw.Stop();
MessageBox.Show(sw.ElapsedMilliseconds.ToString("00:00:000"));
sw.Reset(); 

0 个答案:

没有答案