简体   繁体   中英

C# how to implement a termination handler

I want to serialise an object in C# if a user stops a console application.
I have seen various questions dealing with this, but no final answer.
I will need to catch Ctrl+c, clicking the top right corner and stop process from the task manager.
Is it safe if I have an implementation object and add this as a finalizer to it?

只需处理AppDomain.ProcessExit

In this forum you can find an example of exit event detection. Hope this can help you. http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/707e9ae1-a53f-4918-8ac4-62a1eddb3c4a/

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