I use WebBrowser Control in my Web Application. On DocumentCompleted Event I want DocumentText in my string. My DocumentCompleted Event is like follow.
void IEBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
string str = IEBrowser.DocumentText;
}
Now the problem is DocumentText that I want I don't get it in DocumentCompleted Event. I think there is some javascript that do things after DocumentCompleted event. So I change my code something like this.
void IEBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Thread th = new Thread(new ThreadStart(startthread));
th.Start();
}
public void startthread()
{
//To Wait untill WebBrowser run that javascript
Thread.Sleep(5000);
string str = IEBrowser.DocumentText;
}
Now with this code I am getting "Specified cast is not valid.". How can I make wait for the Thread in which WebBrowser is running?