I am currently working with a webBrowser control in a WinForm
-
public Form1()
{
InitializeComponent();
webBrowser1.AllowNavigation = true;
webBrowser1.Navigate("http://foo.bar");
}
I have a button control that takes the webBrowser1.Url.OriginalString
and sets it to a textBox -
// On button_Click
string requestResponse = webBrowser1.Url.OriginalString;
requestURLtextBox.Text = requestResponse;
However if the button is clicked before webBrowser1
has had enough time to get the OriginalString
text, this will error as the value does not exist yet.
I tried adding -
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Thread.Sleep(1000);
}
Before the previous code in the button_Click event however this went into an infinite loop. How can I retrieve the OriginalString
after the webBrowser is complete?