Is the server side still executing after the ASP.net page is closed? _ Practical Tips
Source: Internet
Author: User
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.
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);
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.
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);
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);
Sw. Write (txt. ToString ());
Sw. Close ();
SW = NULL;
It is important to note that the use of isclientconnected is to occupy a certain amount of system resources.
IsClientConnected actually needs to output something to the client before it knows if the client is still online.
This way, unless your application is time-consuming, it is recommended that you do not use isclientconnected. Lest you judge isclientconnected use more resources than your actual business logic uses.
In any case, response.isclientconnected has some overhead, so it is only used before the operation is performed at least 500 milliseconds (if you want to maintain the throughput of dozens of pages per second, which is a long time). As a general rule, do not call it in every iteration of a tight loop, for example, when a row in a table is drawn, it may be called once every 20 or 50 lines.
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