Solved

Deadlock between two browser controls

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API v SOA 8 37
Popup write two lines 3 21
[form-control] Retain values after a POST action 21 31
Can anyone help me find this preloader? 51 36
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

680 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