By default, HTTP is a back-and-forth request, and the response is returned, even if it is over. This greatly improves the utilization efficiency of web servers. Don't be stuck at the door.
However, in some cases, some people may want to hide them on the page. For example, stock quotations and online chat, after all, it is not good for people to check the stock every few seconds. It is best to notify the browser immediately when the data changes.
This technology uses server push. Http://en.wikipedia.org/wiki/Push_technology (Glossary)
After looking for a long time, I did not find a suitable example. I found one but couldn't be better at it. Then I changed it and ran very well. The principle is quite simple. Write it down for reference. This is the principle of Dynamic Refresh of Yahoo's stock market.
Code
Protected Override Void Render (htmltextwriter output)
{
Base . Render (output );
Response. Buffer= True;
BoolIsoutput= False;
Response. Write ("");
Response. Flush ();
Int Lastsecond = 0 ;
While (Response. isclientconnected)
{
Thread. Sleep ( 300 );
If (Datetime. Now. Second ! = Lastsecond && ! Isoutput)
{
Lastsecond = Datetime. Now. Second;
Response. Write ( " <SCRIPT> settimer (' " + Datetime. Now. tostring () + " ') \ N </SCRIPT> " );
Response. Flush ();
Isoutput = True ;
}
Else
{
Isoutput = False ;
}
}