-1

I have a web browser control that is added to a user control and is automatically made to navigate to a specific URL when an email is selected (lets say https://www.google.com). Whilst the navigation is going on, when clicking through emails, it slows down the actual performance of Outlook and outlook waits for the page to load. Is there a way I could carry out this navigation in the background without actually affecting the performance of Outlook when clicking through various emails?

Thanks.

Update:

AddIn Startup Code:

 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 Code (On Email selection change):

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

Document Completed Code:

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
Neophile
  • 5,660
  • 14
  • 61
  • 107
  • I think web browser control performs its loading tasks without slowing the UI. Did you check resource usage through task manager? – theBugger Oct 20 '16 at 11:14
  • Well, I think they are supposed to, however, in my case there is a lot of loading going on and it takes a lot of time for the web browser content to load. The web page changes based on the current email address as I am passing that through to the web browser control. – Neophile Oct 20 '16 at 11:21
  • It's normal that if your page is heavy, the browser could hang (it happends even with your real-life browser). If the browser is on the same process as outlook it will make everyone slower. – theBugger Oct 20 '16 at 11:32
  • Is there a way I could make this web browser control run on a different thread or something so that it doesn't affect the performance of Outlook in general? – Neophile Oct 20 '16 at 11:33
  • It should be run on another **process**, it's not the same as a Thread. But I really don't know if this is possible. – theBugger Oct 20 '16 at 11:36
  • 2
    There's lack of detail in the question to help you. Loading the web browser needs to be on a separate thread as already mentioned. You didn't post any code you have tried therefore we can't help you if we can't see what you are doing... Please update your post if you want a great answer. – Trevor Oct 21 '16 at 00:20
  • Ok sure @Zaggler. I will add that as well. – Neophile Oct 21 '16 at 09:21
  • I have added some code @Zaggler. Please let me know if you need more information. – Neophile Oct 22 '16 at 09:37

1 Answers1

1

I suppose you are using System.Windows.Forms.WebBrowser.

There is a Stop() method you could try to call before you request a new Navigate(String).

habakuk
  • 2,712
  • 2
  • 28
  • 47
  • How is this going to help? Will it stop the existing navigation/stop the web browser control from loading what it was loading before? Also since the page is big and the DOM takes time to load, once I have clicked on an email, it takes a lot of time to show the web page and because of this it makes it difficult to click on another email till this page is loaded. – Neophile Oct 27 '16 at 09:17
  • @JackBrown The documentation says "Cancels any pending navigation". But I don't know whether it helps in your concrete scenario or not. – habakuk Oct 27 '16 at 11:34
  • Is there a way I could run this web browser control on a separate thread so that it doesn't interfere with the UI? – Neophile Nov 18 '16 at 17:32