How to run code before program exit? [duplicate]
问题 This question already has answers here : Capture console exit C# (10 answers) Closed 5 years ago . I have a little console C# program like Class Program { static void main(string args[]) { } } Now I want to do something after main() exit. I tried to write a deconstructor for Class Program, but it never get hit. Does anybody know how to do it. Thanks a lot 回答1: Try the ProcessExit event of AppDomain : using System; class Test { static void Main(string[] args) { AppDomain.CurrentDomain