On the DocumentCompleted event, MSDN explained that the document was executed after loading, but in my program documentcompleted was repeatedly called, check the information, there are probably the following situations.
1, WebBrowser load a page documentcompleted event will be executed two times, but these two times readystate state is not the same, respectively, intercative and complete. MSDN's interpretation of these two status values is complete the control has finished loading the new document and all its contents; Interactive the control has loaded enough documents to allow limited user interaction, such as clicking a hyperlink that has been displayed. This shows that, in fact, the DocumentCompleted event will be called once in the interactive state and the complete state, then we can determine exactly what we need to do according to our needs. The workaround instance code is as follows:
The code is as follows:
if (Webbrowser1.readystate!=webbrowerreadystate.complete)
Return
2. If a page contains multiple frames pages, it is also possible to trigger a documentcompleted event when each frame page is loaded (MSDN explains that it is documentcomplete to get triggered multiple times in the case of multiple frames. Not every framework will trigger this event, but each frame that triggers the Downloadbegin event will trigger the corresponding DocumentComplete event. In this case the workaround instance code is as follows:
The code is as follows:
if (e.url.tostring ()!=webbrowser1.url.tostring ())
Return
In addition, MSDN provides a different scenario, as described in:
3, for the above two cases I did not meet, but encountered a third situation: In my documentcompleted incident executed the corresponding code, the result triggered a documentcompleted event, so cyclical, endless. Use Webbrowser1.stop (), still can't stop. Webbrowser1.nagviate ("About:blank") is still the problem. At this point we can only unload the DocumentCompleted event, that is, after executing the code you need in the DocumentCompleted event, another sentence:
The code is as follows:
webbrowser1.documentcompleted-= new Webbrowserdocumentcompletedeventhandler (webbrowser1_documentcompleted);
In addition to the Declaration,Running GuestArticles are original, reproduced please link to the form of the address of this article
Webbrowser.documentcompleted event multiple invocation problem resolution in C #
This address: http://www.paobuke.com/develop/c-develop/pbk23165.html
Related Content C # the way to filter HTML tags and retain specified labels C # implements a method for converting a picture to binary and converting a binary to a picture C # The timer uses and solves the reentrant problem summary of methods for converting a DataTable to JSON in C # (three methods)
The function of commodity lottery in C # MVC mode realization of polymorphism and polymorphism in C # devexpress pie chart highlighting (Explode) setting an instance call a method of a non-managed DLLs from a C # program
Webbrowser.documentcompleted event multiple invocation problem resolution in C #