-
December 20th, 2018, 08:23 AM
#1
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:
Web Change Tracker bug #0001_01.jpg
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.
-
December 20th, 2018, 12:49 PM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|