Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to execute a portion of code (the state save) on the process stopping - by itself, by user, by task manager, etc.

Is it possible?

try {} finally {}, AppDomain.ProcessExit, IDisposable, destructor,.. what next to try?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
254 views
Welcome To Ask or Share your Answers For Others

1 Answer

As others have pointed out, there is no way you can execute any code in your application when it is being Killed by Operating System or User. That is why its called Killing.

If saving the state is an important part of your application, you should take an approach similar to a database system. Implementing transaction log, creating checkpoints, etc. That is the closest you can get.

In that case, when your application revives (is re-run after being killed), it can check these transaction logs for any pending updates or last state changes.

Other than that, it really depends on what you want to do. And also why you came up with this idea? Can we get more details? May be someone here has better alternative.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...