【问题标题】:Web browser control loading Outlook unusable VB.NetWeb 浏览器控件加载 Outlook 无法使用 VB.Net
【发布时间】:2017-02-27 01:51:57
【问题描述】:

我有一个 Web 浏览器控件,它添加到用户控件中,并在选择电子邮件时自动导航到特定 URL(比如说https://www.google.com)。在导航过程中,当单击电子邮件时,它会减慢 Outlook 的实际性能,并且 Outlook 会等待页面加载。有没有办法在点击各种电子邮件时在后台执行此导航而不实际影响 Outlook 的性能?

谢谢。

更新:

插件启动代码:

 Private Sub ThisAddIn_Startup() Handles Me.Startup

        myUserControl1 = New OutlookTaskPane
        myUserControl1.TabStop = True
        Dim width As Integer = myUserControl1.Width
        myCustomTaskPane = Me.CustomTaskPanes.Add(myUserControl1, "Title")
        myCustomTaskPane.Width = width
        myCustomTaskPane.Visible = True
        myCustomTaskPane.DockPositionRestrict = Microsoft.Office.Core.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange

        currentExplorer = Me.Application.Explorers.Application.ActiveExplorer
        AddHandler currentExplorer.SelectionChange, AddressOf myOutlookExplorer_SelectionChange
    End Sub

SelectionChange 代码(电子邮件选择更改):

Private Sub myOutlookExplorer_SelectionChange() Handles currentExplorer.SelectionChange
        Dim RandNum As Integer = myUserControl1.GetRandomNumber(1, 100)
        ' Grid Loading Link
        myUserControl1.WebBrowser1.Navigate("https://www.google.com" & "?" & RandNum, Nothing, Nothing, "User-Agent:  Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko")
    End Sub

文档完成代码:

Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        ' If the document is not completely ready, then don't perform the events below
        If Not WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
            Return
        End If
.... // lots of field setting/DOM manipulation after the DOM is loaded
End Sub

【问题讨论】:

  • 我认为 Web 浏览器控件执行其加载任务时不会减慢 UI。你有没有通过任务管理器查看资源使用情况?
  • 好吧,我认为他们应该这样做,但是,在我的情况下,正在进行大量加载,并且加载 Web 浏览器内容需要很长时间。当我将当前电子邮件地址传递给 Web 浏览器控件时,网页会根据当前电子邮件地址进行更改。
  • 如果您的页面很重,浏览器可能会挂起是正常的(即使您使用现实生活中的浏览器也会发生这种情况)。如果浏览器和outlook在同一个进程,那会让大家变慢。
  • 有没有办法让这个 Web 浏览器控件在不同的线程上运行或其他什么东西,这样它一般不会影响 Outlook 的性能?
  • 问题中缺少帮助您的细节。如前所述,加载 Web 浏览器需要在单独的线程上。您没有发布您尝试过的任何代码,因此如果我们看不到您在做什么,我们将无法帮助您...如果您想要一个好的答案,请更新您的帖子。

标签: vb.net email outlook webbrowser-control loading


【解决方案1】:

我猜你正在使用System.Windows.Forms.WebBrowser

在请求新的Navigate(String) 之前,您可以尝试调用Stop() 方法。

【讨论】:

  • 这有什么帮助?它会停止现有的导航/停止 Web 浏览器控件加载之前加载的内容吗?此外,由于页面很大并且 DOM 需要时间来加载,一旦我点击了一封电子邮件,显示网页需要很长时间,因此很难点击另一封电子邮件,直到这个页面已加载。
  • @JackBrown 文档说“取消任何挂起的导航”。但我不知道这对您的具体情况是否有帮助。
  • 有没有办法让我在单独的线程上运行这个 Web 浏览器控件,这样它就不会干扰 UI?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-26
  • 2018-08-13
  • 1970-01-01
  • 2010-11-03
  • 2019-08-24
相关资源
最近更新 更多