Question Cannot Debug with Webbrowser on a different Form

adrian1906

Member
Joined
May 29, 2011
Messages
5
Programming Experience
10+
I have an application that loads a website into a webbrowser control that is on another form (Form2). Unfortunately, during debugging, the contents of the webbrowser does not show. The remainder of my program depends on the information obtained from the loaded website but since it does not show, I am unable to enter the the necessary information, thus the code does not advance.

The debugging works fine if the browser is located in the initial form (Form1)

Is there a setting that in VS 2010 that will fix this?

Thank you.
Adrian
 
There's no setting that will make bad code work. If it doesn't work then you're doing it wrong. If we can't see what you're doing then we can't tell you what you're doing wrong. My guess would be that it has something to do with default instances but that's just a guess. You need to post the relevant code and, please, only the relevant code.
 
jmcilhinney,

Thank you for your response.

I attached a project that illustrates what I am talking about. It consists of 2 forms. Form1 has only a label and a button. The button calls Form2 which loads a browser and navigates to facebook.com. The code then waits for the user to login and then it retrieves the resulting URL.

(Note: actual facebook authentication process is a little more involved but this trimmed version is suffice to illustrate the problem I am having)

Thanks in advance for any assistance you can provide.

Adrian
 

Attachments

  • TestBrowserInForm2.zip
    20 KB · Views: 20
Last edited by a moderator:
The code then waits
That code is blocking the UI thread. What you should do is to get rid of that loop, handle the browser.DocumentCompleted event in second form, and take it from there.
 
Resolved: Cannot Debug with Webbrowser on a different Form

JohnH,

Handling the browser.DocumentCompleted event is a more sound approach. Especially since I am closing the window right after the log in.
 
Back
Top