Webbrowser.documentcompleted event multiple invocation problem resolution in C #

Source: Internet
Author: User

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.