Question: When an ongoing ASPX page executes halfway through the browser, you close the page and the server-side code for this page is still executing?
Answer: Unless you make a special judgment in your code, you are still executing.
Note the point:
1, the client Display page, the background has been executed by the Page object has not existed. Of course this is not a problem with server segment execution.
2, the page has not returned, in the waiting state. Closing the ASPX page will involve situations where the server side mentioned above is still executing.
3. When the client shuts down, it does not send instructions to the server at all.
4, unless you make a special judgment in the code, here the special judgment refers to the IF (! response.isclientconnected) to detect the status and terminate the operation with code.
The following simple code is a demo of closing the page to see if it's still executing?
You can turn this page off when you have not returned any information after the page is opened, and then see if any corresponding files are created and filled out in the specified directory.
protected void Page_Load (object sender, EventArgs e)
{
StringBuilder txt = new StringBuilder ( );
txt. Appendline ();
txt. Appendline (DateTime.Now.ToString ("U"));
txt. Appendline ("ASVD");
Response.Write (DateTime.Now.ToString ("U"));
Response.Write ("\ r \ n");
Thread.Sleep (50000);
txt. Appendline (DateTime.Now.ToString ("U"));
Response.Write (DateTime.Now.ToString ("U"));
Response.Write ("\ r \ n");
//write some information to another file to see if it is running
string dir = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "logs");
if (! Directory.Exists (dir))
Directory.CreateDirectory (dir);
DateTime dt = DateTime.Now;
String shortfilename = string. Format ("Errors_{0:0000}{1:00}{2:00}.log", dt. Year, dt. Month, dt. Day);
String fileName = Path.Combine (dir, ShortFileName);
StreamWriter SW;
if (file.exists (fileName))
SW = File.appendtext (fileName);
Else
SW = File.createtext (fileName);
Sw. Write (txt. ToString ());
SW. Close ();
SW = null;
}
A simple example of a special judgment:
Note: IsClientConnected's judgment is not supported by the development site ASP.net Development Server that vs.net development tools bring. asp.net Development Server returns True forever.
IIS is supported.
protected void Page_Load (object sender, EventArgs e)
{
StringBuilder txt = new StringBuilder () ;
for (int i = 0; i < i++)
{
if (this. response.isclientconnected)
{
txt. Appendline ();
txt. Appendline (DateTime.Now.ToString ("U"));
txt. Appendline (i.ToString ());
Response.Write (DateTime.Now.ToString ("U"));
Response.Write ("\ r \ n");
Thread.Sleep (500);
}
Else
{
Response.End ();
Return
}
}
txt. Appendline (DateTime.Now.ToString ("U"));
Response.Write (DateTime.Now.ToString ("U"));
Response.Write ("\ r \ n");
//write some information to another file to see if it is running
string dir = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "logs") ;
if (! Directory.Exists (dir))
Directory.CreateDirectory (dir);
DatetIME dt = DateTime.Now;
String shortfilename = string. Format ("Errors_{0:0000}{1:00}{2:00}.log", dt. Year, dt. Month, dt. Day);
String fileName = Path.Combine (dir, ShortFileName);
StreamWriter SW;
if (file.exists (filename))
SW = file.appendtext (filename);
else
SW = File.createtext (fileName);
Sw. Write (txt. ToString ());
SW. Close ();
SW = null;
}