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

    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:

    Code:
    Dispatcher.Invoke(new Action(() => { webBrowser.Source = siteUri; }));
    Dispatcher.Invoke(new Action(() => { labelWebBrowserPreview.Content = url; }));
    
    System.Threading.Thread.Sleep(30000);
    
    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: 933
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
    Posts
    13,490

    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

Featured