Solved

Deadlock between two browser controls

Posted on 2008-10-20
1
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
tom3030 earned 0 total points
ID: 22756382
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

729 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