I want to do something after the document have completely load… I dont want to use WebBrowser.DocumentCompleted Event, so please don’t suggest me this.
I tried 2 ways to do it but they not work. Can someone tell me what I doing wrong?
Example 1
wb.Navigate("http://www.google.com");
while(wb.ReadyState != WebBrowserReadyState.Complete) { }
richtextdocument.Text = wb.DocumentText;
Example 2
wb.Navigate("http://www.google.com");
while(wb.isBusy == true) { }
richtextdocument.Text = wb.DocumentText;
What you are dealing with here is trying to call an inherently asynchronous method synchronously.
As you mentioned in the comments to your question that the reason for not using
DocumentCompletedis that you will need to use that event for other purposes, what I suggest you do is to use theDocumentCompletedevent, coupled with a private class boolean flag to determine if this is the special case ofDocumentCompletedor not.This will still allow you to control other cases within the event handler.
You must take special care to ensure that your user is not able to trigger another call to
Navigate()before this ‘special action’ page finishes loading, otherwise it may steal the special case event. One way could be to block the UI until the page finishes loading, e.g.: