WinForm WebBrowser 控件加载缓慢。预加载的最佳方法?
我们的 winform 应用程序中有一个摘要视图,它使用 WebBrowser 控件来显示网页中的摘要信息。我们使用它来获得一些丰富的表格布局,这是使用标准 winform 控件无法实现的。第一次在客户端上显示视图时,需要一段时间才能启动(我假设在后台启动 IE),并且应用程序冻结了相当多的几秒钟。我正在考虑某种预加载机制,可以让 IE 在后台启动,并且需要一些社区指导。
我正在考虑在应用程序启动时使用网络浏览器控件启动屏幕外或不可见的表单,或者在应用程序启动时在某种侧线程中启动 IE 实例。
有什么建议吗?
We have a summary view in our winform app that uses a WebBrowser control to display the summary information from a web page. We are using this to gain some rich tabular layout that we could not accomplish using standard winform controls. the first time the view is displayed on the client it takes a while to spin up (launching IE in the background i assume) and the app freezes for quite a few seconds. I'm considering some sort of pre-loading mechanic that would get IE spun-up in the background and would like some community guidance.
I'm considering launching an off-screen or invisible form with a webbrowser control at app start or launching an IE instance in some sort of side thread at app start.
any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在应用程序启动期间在单独的线程中预加载控件。
请注意 STA 单元状态,如果您想要操作某些 COM 对象(如 Web 浏览器),则该状态是必需的。
You can preload the controls during the application startup, in a separate thread.
Note the STA apartment state, which is mandatory if you want to manipulate some COM objects (like the WebBrowser).
我没有经历过您提到的启动滞后,但作为一个想法,在启动时您可以导航到
about:blank
。然后,在浏览器的DocumentCompleted
事件中,您可以开始导航到正确的 URL。这可能会帮助您了解到底是您的“IE 启动”占用了所有时间,还是内容查询和渲染占用了时间。就您的架构而言,除非您的“丰富的表格布局”已经构建并且功能齐全,否则您可能会考虑使用 WPF(它也有一个很好的 WinForms 集成故事),以便在您的应用程序中获得一些更丰富、更性感的控件。
I've not experienced the start up lags you mention, but as an idea, on start-up you could navigate to
about:blank
. Then on browser'sDocumentCompleted
event you could kick off a navigation to your proper URL. That might help you understand whether it's your "IE spin-up" that's taking all the time or the content query and render.In terms of your architecture, unless of course your "rich tabular layout" is already built and fully functional then you might consider using WPF (it has a good WinForms integration story too) in order to get some richer and sexier controls into your app.