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
Solved

Deadlock between two browser controls

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

791 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