Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# how to implement a termination handler

Tags:

c#

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?

like image 814
weismat Avatar asked Sep 02 '26 13:09

weismat


1 Answers

Just handle AppDomain.ProcessExit.

like image 100
jason Avatar answered Sep 05 '26 02:09

jason