Solved

Deadlock between two browser controls

Posted on 2008-10-20
1
285 Views
Last Modified: 2012-05-05
I have a situation with a Vb.Net project where two WebBrowser controls are getting caught in a deadlock, because Browser1 is waiting for a page on Browser 2 to be ready so it can open a print dialog box (see Javascript code snippet) and Browser 2 can't finish loading a page because the Javascript loop on Browser 1 is consuming the available CPU cycles for the main thread (and causing everything to lock up). Although this does not happen between two normal I.E. windows the main browser thread cannot be in stand-alone I.E. - it has to be in the WebBrowser control. My questions are :-

Can two webBrowser control windows be run in seperate threads (i.e. can a popup window that maintains session state of the main window run seperately from the main UI)?

If not, can JavaScript execution or the browser control itself be paused (mid function) within a WebBrowser control via .Net code (i.e. can I suspend a javascript 'loop' while something else completes)?

If not can a popup/child page be opened in I.E. that maintains the session from the WebBrowser control (i.e. so a user does not have to log in again in this window)?

If not can a geniune pause/sleep be achieved in javascript (i.e. for not hogging CPU resources in a nested loop)? (This would be a last resort as I do not own or have control of the Javascript)
//Javascript from first page (in browser control 1)

printWin = window.open("Print.htm","Print","toolbar=no,menubar=yes,scrollbars=yes,resizable=yes");

//SOME CODE REMOVED

do {} //Causing lockup.

while (printWin.document.readyState!='complete')

Open in new window

0
Comment
Question by:tom3030
1 Comment
 

Accepted Solution

by:
tom3030 earned 0 total points
Comment Utility
I've managed to solve my own problem by making the second WebBrowser control run on a seperate thread. Contrary to all the internet posts that say you cannot run the WebBrowser control on a seperate thread you can. I have attached the code used to create the second control on a seperate thread and set the display page to that instance.
    Private Sub Web_V1_NewWindow(ByRef ppDisp As Object, ByRef Cancel As Boolean) Handles Web_V1.NewWindow2
 
 

        Dim T As Thread

        T = New Thread(AddressOf LaunchWB2)

        T.IsBackground = True

        T.SetApartmentState(ApartmentState.STA)

        T.Start()
 

            Do While SecondForm Is Nothing OrElse Not SecondForm.Created

                Application.DoEvents()

            Loop
 

            Do While SecondForm.WebBrowser1.ActiveXInstance Is Nothing

                Application.DoEvents()

            Loop
 

            ppDisp = SecondForm.WebBrowser1.ActiveXInstance

           

    End Sub
 

    Private Sub LaunchWB2()

        SecondForm = New Form2

        Application.Run(SecondForm)

    End Sub

Open in new window

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now