Using the webbrowser control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • boxim

    Using the webbrowser control

    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
    DocumentComplet e 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


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Using the webbrowser control

    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.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "boxim" <sambomartin@ya hoo.co.uk> wrote in message
    news:uJtCox$kDH A.964@TK2MSFTNG P10.phx.gbl...[color=blue]
    > 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[/color]
    events[color=blue]
    > 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[/color]
    the[color=blue]
    > HTML document is refreshed.
    >
    > Obviously, the hooking of element events to methods in my C# application[/color]
    can[color=blue]
    > occure only after the HTML Document has finished loading - so i do it on[/color]
    the[color=blue]
    > DocumentComplet e event. But the page is obviously loaded by the[/color]
    WebBrowser[color=blue]
    > control by one or more threads, so do I need to build in thread safety[/color]
    when[color=blue]
    > processing these events?
    >
    > I just need someone really to say, yes you're doing it the right way....[/color]
    if[color=blue]
    > I am?
    >
    > TIA
    >
    > Sam Martin
    >
    >[/color]


    Comment

    Working...