简体   繁体   中英

ASP.Net Application Data not updating when application forcibly end

I have asp.net application.

I am forcibly ending this application and on the time of that i want to update my view page count value in database .

I am forcibly stopping my application that time Application_End() not firing in Global.aspx file. when i stop process normally then Application_End() event fired. but my requirement is that,

Data should be update in both cases forcibly or gracefully stop application. Suggest me for better solution or what other event should i use.

void Application_End(object sender, EventArgs e)
{
// Code that runs on application shut`enter code here`down
}

If I where you i would take a look at this question: How to detect a Kill Process event

One of the comment says

My point is this... you can't depend on getting a chance to save data, particularly in case of unexpected termination of your process. You can certainly try to do this as much as possible, but you have to be aware that there will always be some event that could cause your application to exit without giving you a chance to save data. (For instance, the system's power cord could be unplugged.) I don't mean to be picky, I just wanted to point this out for others with a similar question. -reuben

If the kind of data you are working with really are crutial, i would recommend saving them at the moment you are able to do it. waiting for the application to be shutted down before saving data is asking for trouble.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM