Solved

Deadlock between two browser controls

Posted on 2008-10-20
1
291 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Download a website to hdd 2 51
Variable Event ? 3 23
Google Sheets script efficiency 2 4
how can i select 4 9
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

867 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

19 Experts available now in Live!

Get 1:1 Help Now