
Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Thank you for your reply. I've added a Load method to my user control and
it does seem to address the problems I'm having. Let me provide greater
details.
I've constructed a user control that contains only an axWebBrowser control
(the browser control completely fills or covers the user control panel).
This user control contains the following methods: ClearContents, SetContents
and Navigate. Navigate does pretty much what you've outlined below.
ClearContents navigates to "about:blank" and SetContents navigates to
about:blank and within the captured DocumentComplete event writes a content
string into the HTML document. I'm doing a lot of dynamic HTML creation and
the user control is an abstraction that helps hide the details of pushing a
HTML string into a browser. Mostly this works very well except when Dispose
it executed. ... as an example here is what ClearContents looks like:
public void ClearContent() {
m_browserAction = BrowserAction.Clear;
m_browserState = BrowserState.Requested;
object n = null;
if (this.InvokeRequired == true) {
this.Invoke(new NavigateBrowser(m_browser.Navigate), new
object[] { "about:blank", n, n, n, n} );
}
else {
m_browser.Navigate("about:blank", ref n, ref n, ref n, ref
n);
}
}
In my application I make heavy use of the above control, and place it on
several panels in a tab control. In my application I had to code this loop
in my application's Dispose method:
// run thru all the tab pages so you don't get a dispose error (which
gets thrown if the BrowerControl doesn't get it's window shown
for (int i = 0; i < m_tcMain.TabPages.Count; i++) {
m_tcMain.SelectedIndex = i;
}
If I do not touch all the tabs, then in the user control's dispose method
"base.Dispose(disposing)" throws a
System.Reflection.TargetInvocationException ("Unable to get the window
handle for the 'AxWebBrowser' control. Windowless ActiveX controls are not
supported"). Initially in the browser user control, I called ClearContent
from within the Contructor, but on your recommendation I moved this call to
the Load method. However, when I remove the "tab touch loop in the
application, I still get the TargetInvocationException throw. After that
exception is thrown a couple of times I get a NullReferenceException
("Object Reference not set to an instace of an object") in "main" of the
application.
I can avoid this problem by creating a static bool in the browser user
control that ensures that the Dispose method runs only once regardless of
how many instances of the control exists. However, doing this without
understand why isn't exactly appealing. If I had to guess I would say that
some part of the AxWebBrowser is shared across all instances of the object
and that the first object that dispose of it, leave all the other instances
broken.
Thanks
> Hi
>
[quoted text clipped - 24 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
"Peter Huang" [MSFT] - 15 Jun 2005 03:56 GMT
Hi
Based on my understanding, you will have multiple webbrowser controls
instance on the tab control simultaneously.
I think you may try to initialize all the webbrowser control instances in
the tab control's load event just as I last post.
Also from the exception it seems that when we try to dispose the webbrowser
control, the instance has been disposed which caused the problem.\
You may check if there is any code in your program will dispose the
webbrowser.
If my above suggestion did not work for you, would you please simplify your
reproduce sample as possible.(e.g. if the html operation did not affect
reproduce the problem, we can just comment them out temporarily and send to
me via removing "online" from my email address, so that we do can further
troubleshooting.
Thanks for your efforts.
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT] - 22 Jun 2005 07:52 GMT
Hi Greg,
Based on my test, it seems that the sample works fine at my side.
Here is my reproduce steps.
1. Add the two projects into a test solution
2. compile and press F5/ Ctrl+F5 to run the project
3. Click button1 to load tabpage1/2
4. close the application
5. close the ide
I did not get any exception, did I miss some thing?
Also I wonder why you need to do the dispose method.
Commonly dispose is used to release the unmanaged resource.
Althrough Webbrowser control is unmanaged component, but the RCW layer
which is the layer between .NET and COM will do the release job.
so commonly we do not need dispose here.
Also I have add more button in the test form and try to call the
browserControl1.Dispose method, and the control is disposed and have no
exception.
private void button1_Click(object sender, System.EventArgs e) {
browserControl1.SetContent("<html><body>Hello. How are you?</body></html>");
browserControl2.SetContent("<html><body>I'm fine thanks, how are
you?</body></html>");
}
private void button2_Click(object sender, System.EventArgs e)
{
this.browserControl1.Dispose();
}
Did I miss something?
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.