首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复WatiN OutOfMemoryException

如何修复WatiN OutOfMemoryException
EN

Stack Overflow用户
提问于 2011-12-26 08:14:47
回答 2查看 466关注 0票数 0

我用WatiN迭代了一个非常大的div列表(大约3000个),我得到了错误:

代码语言:javascript
复制
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时。

有谁知道如何解决内存问题吗?我希望我可以使用不同的函数或以某种方式拆分页面。也许我需要使用WatiN之外的其他东西

代码是:

代码语言:javascript
复制
 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
                            {

谢谢你的帮助

克里斯

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-12-29 05:45:17

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

在我的例子中,在64位系统上运行“修复”(或者更确切地说,延迟)了这个问题。

票数 0
EN

Stack Overflow用户

发布于 2011-12-26 19:45:29

首先,当您等待页面时,不要使用用户线程睡眠,您可以使用browser.WaitForComplete()

如果你正在查看链接是否将你带到特定的页面,你可以像这样直接检查浏览器的url : browser.Url.Contains("address") ...

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8632259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档