2011-12-26 82 views
0

我遍历的div与华廷非常大名单(约3000),我得到的错误:如何解决华廷OutOfMemoryException异常

A first chance exception of type 'System.OutOfMemoryException' occurred in WatiN.Core.dll 
System.OutOfMemoryException: Insufficient memory to continue the execution of the program. 
    at WatiN.Core.UtilityClasses.UtilityClass.TryFuncFailOver[T](DoFunc`1 func, Int32 numberOfRetries, Int32 sleepTime) 
    at WatiN.Core.Native.InternetExplorer.IEElement.GetWithFailOver[T](DoFunc`1 func) 
    at WatiN.Core.Native.InternetExplorer.IEElement.GetAttributeValue(String attributeName) 
    at WatiN.Core.Element.GetAttributeValueImpl(String attributeName) 
    at WatiN.Core.Component.GetAttributeValue(String attributeName) 
    at WatiN.Core.Element.get_OuterHtml() 
    at WatiN.Core.Document.get_Html() 

当点击一个div然后让的的HTML浏览器。

有谁知道如何解决内存问题?我希望我可以使用不同的功能或以某种方式分割页面。也许我会需要使用其他的东西比华廷

的代码是:

foreach (Div d in browser.Divs) 
        { 

         try 
         { 
          d.Click(); // click div 

          System.Threading.Thread.Sleep(250); //wait for new data to load 

          string url = ""; 
          if (browser.Html.Contains("http://www.google.com/url?")) // check if an external link exists on the page - this causes the memory exception 
          { 

感谢所有帮助

克里斯

+0

取悦过去包含该代码的完整的方法..这样一看就明白到底什么是你甚至试图做..例如d.Click()什么样的代码背后有发生。这看起来相当凌乱条款代码逻辑 – MethodMan 2011-12-26 00:49:08

回答

0

在这种情况下,它是一个Internet Explorer的问题,因为它使用的内存量超过了1GB,并且可能达到了32位.net对象限制某处。

在我的情况下,64位系统的“固定”上运行(或者说,延迟)的问题。

0

先不要用户线程睡眠时,你等待页面,你有browser.WaitForComplete()

如果你正在寻找检查该链接带你到特定的页面,您可以检查直接在浏览器URL像这个:browser.Url.Contains(“地址”)...

+0

请注意,Chris可能正在等待AJax或类似的异步调用以完成Thread.Sleep()。不是最好的方式,但WaitForComplete不适用于AJax-y加载。 – OCary 2011-12-28 18:06:28

+0

嗨,因为它发生我正在等待ajax,需要thread.sleep - 我应该已经发布了足够的代码,以清除此问题 – chris 2011-12-28 21:43:11

+0

对不起,错过了这一点。 – alonp 2012-01-01 12:10:23