问题:
I have a console application that contains quite a lot of threads.我有一个包含相当多线程的控制台应用程序。 There are threads that monitor certain conditions and terminate the program if they are true.有些线程会监视某些条件并在它们为真时终止程序。 This termination can happen at any time.这种终止可能随时发生。
I need an event that can be triggered when the program is closing so that I can cleanup all of the other threads and close all file handles and connections properly.我需要一个可以在程序关闭时触发的事件,以便我可以清理所有其他线程并正确关闭所有文件句柄和连接。 I'm not sure if there is one already built into the .NET framework, so I'm asking before I write my own.我不确定 .NET 框架中是否已经内置了一个,所以我在编写自己的框架之前先询问一下。
I was wondering if there was an event along the lines of:我想知道是否有这样的事件:
MyConsoleProgram.OnExit += CleanupBeforeExit;