CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2014

    Problem with a dispatcher/web browser after the program is running for several hours

    The following code can run for several hours with no issues, the problem is that it keeps crashing randomly:

    Dispatcher.Invoke(new Action(() => { webBrowser.Source = siteUri; }));
    Dispatcher.Invoke(new Action(() => { labelWebBrowserPreview.Content = url; }));
    result = Dispatcher.Invoke(() =>
    { return webBrowser.Document; });
    mshtml.HTMLDocument document = result as HTMLDocument;
    string source ="";
    if (document != null)
        var x = document.doctype;
        source = document.documentElement.innerHTML;
    The basic idea is to check websites around every 15 minutes and get the web browser content.

    I highly suspect that it is because I do not check correctly if the document.doctype is correctly set.

    I looked around on the web a little and sleep was the only way I could think of to let some time for the web browser to load the page correctly with a dispatcher.

    The following error is what crashes the application:

    Name:  Web Change Tracker bug #0001_01.jpg
Views: 630
Size:  33.2 KB

    Note: This is a WPF application.

    May you give some help with this please?

    Thank you for your time and help, it is greatly appreciated.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004

    Re: Problem with a dispatcher/web browser after the program is running for several ho

    Rather than sleeping, use a loaded event to get triggered when the page load. Also check the response for an error before checking the doctype.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width