.NET WebBrowser控件和Dispose()方法 [英] .NET Webbrowser Control and Dispose()

查看:640
本文介绍了.NET WebBrowser控件和Dispose()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是有许多的问题和答案的热门讨论的话题,但我仍然没有找到对以下问题的解决方案:

I know this is a hot discussed topic with many questions and answers but I still do not find the solution for the following problem:

我有一个多标签的应用。在每一个选项卡是一个WebBrowser控件。 由于化网页浏览器需要为每一个新的标签更是更多的内存和不自由的标签,关闭这个记忆,我决定在标签关​​闭事件处理程序Webbrowser.Dispose()。这帮助了我关于内存泄漏。所有使用的RAM现在是免费的收盘后。

I have a multi-tab application. On every tab is a Webbrowser control. As the webbrowsers take more an more memory for every new tab and they do not free this memory on tab-close, I decided to make a Webbrowser.Dispose() in the tab close event handler. This helped me concerning the memory leak. all the used RAM is now free after closing.

但是,这引起了新的问题:第一次的Dispose()后,似乎会被销毁了所有其他的网页浏览器的对象。 通常我只能登录到弗里斯特网页浏览器。如果我一个添加多个标签,我通常会自动登录。第一处置后()这不工作了,我要登录的每一个新的选项卡。

But this caused a new problem: After the first Dispose() it seems that the session is destroyed for all other Webbrowser objects. Normally I only login in to the frist webbrowser. If I a add several tabs I am normally logged in automatically. After the first Dispose() this does not work anymore and I have to login on every new Tab.

我试图保持旧饼干,并与新的web浏览器又送他们,但这并没有解决问题。本似乎被销毁。

I tried to keep the old cookies and send them again with the new webbrowser but this did not solve the problem. The seems to be destroyed.

推荐答案

所有的web浏览器实例共享的每个进程的基础会话。据<一href="http://stackoverflow.com/questions/1051365/multiple-webbrower-sessions-processes-in-one-window">EricLaw's回答以一个类似的问题,这似乎是不可能的单独的会话。我相信埃里克的语句他曾担任IE项目经理微软

All WebBrowser instances share the session on per-process basis. According to EricLaw's answer to a similar question, it appears to be impossible to separate sessions. I'd trust Eric's statement as he worked as IE program manager at Microsoft.

然而,如果你还是想尝试一些黑客,你可以看的 CoInternetGetSession 。首先,尝试保存并保持到返回引用的 IInternetSession 。此外,你可以看看注册自己的URL命名空间(的 RegisterNameSpace ),并实现可插入协议处理程序可能最终允许否决此限制。

If however you'd still like to try some hacks, you may look at CoInternetGetSession. First, try saving and holding on to the returned reference to IInternetSession. Further, you could look at registering your own URL namespace (RegisterNameSpace) and implementing a pluggable protocol handler which may eventually allow to overrule this restriction.

当然,这听起来像一个矫枉过正,最有可能将于事无补。一个干净的解决方案可能是重新设计逻辑,摆脱饼干和通过URL传递的状态。

Of course, it sounds like an overkill and most likely won't help at all. A clean solution might be to redesign the logic to get rid of cookies and pass the state via URLs.

EDITED :另一个想法,尝试浏览web浏览器实例(说)有关:空白,等待DocumentComplete事件,在实际处置用的Dispose()。

EDITED: Another idea, try to navigate the WebBrowser instance to (say) "about:blank" and wait for DocumentComplete event, before actually disposing of it with Dispose().

这篇关于.NET WebBrowser控件和Dispose()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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