C #: how to resolve multiple WebBrowser. DocumentCompleted events,

Source: Internet
Author: User

C #: how to resolve multiple WebBrowser. DocumentCompleted events,

The DocumentCompleted event is executed after the document is loaded, but DocumentCompleted is called multiple times in my program, the following situations may occur.


1. After WebBrowser loads a page, the DocumentCompleted event is executed twice, but the ReadyState status of the two events is different, namely Intercative and Complete. MSDN explains the two State values: Complete, which has been loaded into a new document and all its content; Interactive, which has loaded enough documents to allow limited user interactions, for example, click the displayed hyperlink. It can be seen that the DocumentCompleted event will be called once in the Interactive and Complete statuses, so we can determine the actual need based on our needs. The solution example code is as follows:

if(webBrowser1.ReadyState!=WebBrowerReadyState.Complete)    return; 

2. If a page contains multiple frame pages, then, a DocumentCompleted event may be triggered when each frame page is loaded. (MSDN explains that the DocumentComplete acquisition is triggered multiple times when multiple frames exist. Not every framework will trigger this event, but each framework that triggers the DownloadBegin event will trigger the corresponding DocumentComplete event ). In this case, the solution instance code is as follows:

if(e.Url.ToString()!=webBrowser1.Url.ToString())    return;

In addition, MSDN provides another solution. For details, see:

3. I did not encounter the above two cases, but encountered the third case: the corresponding code was executed in my DocumentCompleted event, and the result triggered another DocumentCompleted event, this process is endless. WebBrowser1.Stop () cannot be stopped. The webBrowser1.Nagviate ("about: blank") problem persists. At this time, we can only uninstall the DocumentCompleted event, that is, after executing the code you need in the DocumentCompleted event, let's say:

webBrowser1.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);

Reprinted from: http://www.cnblogs.com/rchlz/archive/2009/02/27/1399274.html

Related Articles

WebBrowser. DocumentCompleted event

WebBrowser class

WebBrowser. Url attributes

WebBrowser. Navigate Method


In the C language, what is the symbol (->) and how to use it?

This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.

In the C language, what is the symbol (->) and how to use it?

This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.

Related Article

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.