WebBrowser control... update

by Patrice 7/2/2008 10:08:49 AM

Just to update you on how my web page thumbnails generator (described in my post my WebBrowser experiment ) goes on...

Since this is used on a server, it , as expected, crashed a couple of times per load test... that's not very useful... I brought a little modification to it...  and it didn't crashed since then.... (note that this is not on production servers)

So the first thing I do is that I load the web page using HttpWebRequest and get its stream from HttpWebResponse.GetResponseStream. Once I get the stream I create a new WebBrowser but instead of opening the page from a URL (with WebBrowser.Navigate), I load the stream that I got from HttpWebResponse into my  WebBrowser's DocumentStream property. And that's it! the rest is the same as before! It's even nicer since I just get the WebBrowser.DocumentCompleted  called once... I don't need to look at the URL to see if it's my main page or an embedded Flash stream... and no more about:blank called after it is completed.

So here is my new method that I have added to my ScreenCapturerSTA class:

 

private void CaptureMS(object obj)
{
    m_byteImg = null;
 
    MemoryStream ms = obj as MemoryStream;
    try
    {
        using (WebBrowser webBrowser = new WebBrowser())
        {
            webBrowser.DocumentCompleted += 
                new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
            webBrowser.Height = 1000;
            webBrowser.Width = 1000;
            webBrowser.ScriptErrorsSuppressed = true;
            webBrowser.ScrollBarsEnabled = false;
            webBrowser.DocumentStream = ms;
            while (!m_done)
            {
                Application.DoEvents();
            }
        }
    }
    catch (Exception ex)
    {
        Trace.WriteLine(ex.ToString());
    }
}

So, just a coincidence? I mean, the WebBrowser still has to load the content...  at least it seems more stable now... 

Next step? hmmm, I'm tempted by a MONO/GECKO experiment...  I might give it a try...

Related posts

Add comment


(Will show your Gravatar icon)  

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

1/6/2009 10:04:55 AM

Powered by BlogEngine.NET 1.3.1.0

LFDX Software Inc.

About the author

P. Lafond Patrice Lafond
(and yes, it's Mr!)
Software Engineer
French Canadian expat in Bermuda for over 7 years.
flag QC  flag BDA

E-mail me Send mail

Calendar

<<  January 2009  >>
MoTuWeThFrSaSu
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Pages

    Recent comments

    Authors

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2009

    Sign in