0

You might say this is a duplicate but I haven't found any helpful answers until now.

I just want to test loading a document. Here is the code. Very simple:

using System;
using System.Windows.Forms;

namespace ConsoleApp1 {
    public class Program {
        static bool completed = false;

        [STAThread]
        static void Main(string[] args) {
            WebBrowser browser = new WebBrowser();

            browser.Navigating += Browser_Navigating;
            browser.Navigated += Browser_Navigated;
            browser.DocumentCompleted += Browser_DocumentCompleted;

            browser.AllowNavigation = true;
            browser.ScriptErrorsSuppressed = true;
            browser.Url = new Uri("https://www.google.de/");

            while (!completed)
                continue;

            Console.ReadKey();
        }

        private static void Browser_Navigated(object sender, WebBrowserNavigatedEventArgs e) {
            Console.WriteLine("Navigated" + System.Environment.NewLine);
        }

        private static void Browser_Navigating(object sender, WebBrowserNavigatingEventArgs e) {
            Console.WriteLine("Navigating..." + System.Environment.NewLine);
        }

        private static void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
            Console.WriteLine((sender as WebBrowser).Document.Title);
            completed = true;
        }
    }
}

The problem is that after that only Navigating... is output to the console. Neither Navigated or DocumentCompleted are called within more than 10 minutes. Am I missing anything. One answer on msdn said I should set Silent to true but it seems like this propertiy has been removed.

Neither setting Url nor Navigate-Method works.

Kaskorian
  • 426
  • 3
  • 18

0 Answers0