Using the webbrowser control

B

boxim

Hi All,

Just after some other opinions really....

We're writing this application that in places implements the WebBrowser
control to make certain bits look nicer as well as make things quicker to
develop. To write each page as an owner drawn control would take ages.

The only thing that bothers me is the comminication between the browser
control and the main application. We're using the mshtml.dll to hook events
to buttons and finding the objects in the HTML pages by extending the DOM
and adding our own attributes to certain HTML elements - this is sort of
ok - but it seems a bit flakey. I.e. lots of re-hooking of HTML element
events, and periodically some elements don't re-hook to a handler after the
HTML document is refreshed.

Obviously, the hooking of element events to methods in my C# application can
occure only after the HTML Document has finished loading - so i do it on the
DocumentComplete event. But the page is obviously loaded by the WebBrowser
control by one or more threads, so do I need to build in thread safety when
processing these events?

I just need someone really to say, yes you're doing it the right way.... if
I am?

TIA

Sam Martin
 
N

Nicholas Paldino [.NET/C# MVP]

Sam,

Don't worry about the threading. The WebBrowser control, because it is
a visual control, is a Single Threaded component. This means that all
access to it is serialized through one thread. Consequently, all events
coming out of it should occur on that same thread as well. Because of this,
you only have to worry about your components being accessed on the UI
thread.

As for finding the objects in the HTML pages, I don't think you should
add your own attributes. I think that you should use the ID attribute and
set it to something unique, using your own scheme.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top